本文整理汇总了Java中net.spy.memcached.CASValue类的典型用法代码示例。如果您正苦于以下问题:Java CASValue类的具体用法?Java CASValue怎么用?Java CASValue使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CASValue类属于net.spy.memcached包,在下文中一共展示了CASValue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testAsyncGets
import net.spy.memcached.CASValue; //导入依赖的package包/类
@Test
public void testAsyncGets() throws Exception {
String value = UUID.randomUUID().toString();
Boolean didSet = memcacheClient.set("key", 0, value).get();
assertTrue(didSet);
Snapshot expectedValues = tracker.snapshot();
expectedValues.increment("get");
CASValue<Object> casValue = memcacheClient.asyncGets("key").get();
assertEquals(value, casValue.getValue());
tracker.validate(expectedValues);
String value1 = UUID.randomUUID().toString();
CASResponse response = memcacheClient.cas("key", casValue.getCas(), value1);
assertEquals(CASResponse.OK, response);
}
示例2: testGets
import net.spy.memcached.CASValue; //导入依赖的package包/类
@Test
public void testGets() throws Exception {
String value = UUID.randomUUID().toString();
Boolean didSet = memcacheClient.set("key", 0, value).get();
assertTrue(didSet);
Snapshot expectedValues = tracker.snapshot();
expectedValues.increment("get");
CASValue<Object> casValue = memcacheClient.gets("key");
assertEquals(value, casValue.getValue());
tracker.validate(expectedValues);
String value1 = UUID.randomUUID().toString();
CASResponse response = memcacheClient.cas("key", casValue.getCas(), value1);
assertEquals(CASResponse.OK, response);
}
示例3: testAsyncGetAndTouch
import net.spy.memcached.CASValue; //导入依赖的package包/类
@Test
public void testAsyncGetAndTouch() throws Exception {
if (serverSupportsTouch()) {
return;
}
String value = UUID.randomUUID().toString();
Boolean didSet = memcacheClient.set("key", 0, value).get();
assertTrue(didSet);
Snapshot expectedValues = tracker.snapshot();
expectedValues.increment("gat");
CASValue<Object> casValue = memcacheClient.getAndTouch("key", 0);
assertEquals(value, casValue.getValue());
tracker.validate(expectedValues);
String value1 = UUID.randomUUID().toString();
CASResponse response = memcacheClient.cas("key", casValue.getCas(), value1);
assertEquals(CASResponse.OK, response);
}
示例4: testGetAndTouch
import net.spy.memcached.CASValue; //导入依赖的package包/类
@Test
public void testGetAndTouch() throws Exception {
if (serverSupportsTouch()) {
return;
}
String value = UUID.randomUUID().toString();
Boolean didSet = memcacheClient.set("key", 0, value).get();
assertTrue(didSet);
Snapshot expectedValues = tracker.snapshot();
expectedValues.increment("gat");
CASValue<Object> casValue = memcacheClient.getAndTouch("key", 0);
assertEquals(value, casValue.getValue());
tracker.validate(expectedValues);
String value1 = UUID.randomUUID().toString();
CASResponse response = memcacheClient.cas("key", casValue.getCas(), value1);
assertEquals(CASResponse.OK, response);
}
示例5: gets
import net.spy.memcached.CASValue; //导入依赖的package包/类
public static CASValue gets(String key)
{
MemcachedClient client = getClient();
if (client != null)
{
try
{
return client.gets(hashKey(key));
}
catch (Exception ex)
{
logger.error("Memcache get exeption ",ex);
return null;
}
}
else
return null;
}
示例6: testMemcachedException
import net.spy.memcached.CASValue; //导入依赖的package包/类
@Test(groups = "unit")
public void testMemcachedException() {
MemcachedClientIF failingMemcachedClient = mock(MemcachedClientIF.class);
when(failingMemcachedClient.gets(anyString())).thenThrow(
new RuntimeException("Exception waiting for value",
new ExecutionException("Operation timed out", null)));
when(failingMemcachedClient.cas(anyString(), anyLong(), anyObject()))
.thenThrow(
new RuntimeException("Exception waiting for value",
new ExecutionException("Operation timed out",
null)));
MemcachedCacheService failingCacheService = new MemcachedCacheService(
failingMemcachedClient);
CASValue<Object> casValue = failingCacheService.gets(TEST_KEY);
Assert.assertNull(casValue);
CASResponse casResponse = failingCacheService.cas(TEST_KEY, 0L, "1");
Assert.assertNull(casResponse);
}
示例7: testCas
import net.spy.memcached.CASValue; //导入依赖的package包/类
@Test(groups = "functional")
public void testCas() {
cacheService.put(FIRST_TEST_KEY, "0");
CASValue<Object> casValue = cacheService.gets(FIRST_TEST_KEY);
CASResponse casResponse = cacheService.cas(FIRST_TEST_KEY,
casValue.getCas(), "1");
Assert.assertEquals(casResponse, CASResponse.OK);
Assert.assertEquals((String) cacheService.get(FIRST_TEST_KEY), "1");
casValue = cacheService.gets(FIRST_TEST_KEY);
cacheService.put(FIRST_TEST_KEY, "2");
casResponse = cacheService.cas(FIRST_TEST_KEY, casValue.getCas(), "3");
Assert.assertEquals(casResponse, CASResponse.EXISTS);
Assert.assertEquals((String) cacheService.get(FIRST_TEST_KEY), "2");
casValue = cacheService.gets(FIRST_TEST_KEY);
casResponse = cacheService.cas(SECOND_TEST_KEY, casValue.getCas(), "4");
Assert.assertEquals(casResponse, CASResponse.NOT_FOUND);
}
示例8: gets
import net.spy.memcached.CASValue; //导入依赖的package包/类
public com.quickserverlab.quickcached.client.CASValue gets(String key, long timeoutMiliSec)
throws TimeoutException, com.quickserverlab.quickcached.client.MemcachedException{
com.quickserverlab.quickcached.client.CASValue value = null;
try{
OperationFuture <CASValue<Object>> f = getCache().asyncGets(key);
try {
CASValue<Object> cv = (CASValue<Object>) f.get(timeoutMiliSec, TimeUnit.MILLISECONDS);
if(cv != null){
value = new com.quickserverlab.quickcached.client.CASValue(cv.getCas(), cv.getValue());
}else{
throw new com.quickserverlab.quickcached.client.MemcachedException("Object not found");
}
}catch(InterruptedException ie){
throw new com.quickserverlab.quickcached.client.MemcachedException("InterruptedException "+ ie);
}catch(ExecutionException ee){
throw new com.quickserverlab.quickcached.client.MemcachedException("ExecutionException "+ ee);
}catch(java.util.concurrent.TimeoutException te){
throw new TimeoutException("Timeout "+ te);
}finally{
f.cancel(false);
}
}catch(IllegalStateException ise){
throw new com.quickserverlab.quickcached.client.MemcachedException("IllegalStateException "+ ise);
}
return value;
}
示例9: testGets
import net.spy.memcached.CASValue; //导入依赖的package包/类
public void testGets() throws Exception {
MemcachedClient client = bootstrapClient();
client.add("getskey", 10, "casValue").get();
CASValue<Object> val = client.gets("getskey");
long oldCas = val.getCas();
assertEquals("casValue", val.getValue());
client.replace("getskey", 10, "myNewVal").get();
val = client.gets("getskey");
assertEquals(oldCas + 1, val.getCas());
assertEquals("myNewVal", val.getValue());
}
示例10: testCas
import net.spy.memcached.CASValue; //导入依赖的package包/类
public void testCas() throws Exception {
MemcachedClient client = bootstrapClient();
client.add("caskey", 10, "casValue").get();
CASValue<Object> val = client.gets("caskey");
assertEquals("casValue", val.getValue());
CASResponse r = client.cas("caskey", val.getCas(), "newValue");
assertEquals(CASResponse.OK, r);
r = client.cas("caskey", val.getCas(), "newValue2");
assertEquals(CASResponse.EXISTS, r);
}
示例11: testGetsAfterAdd
import net.spy.memcached.CASValue; //导入依赖的package包/类
@Test
public void testGetsAfterAdd() {
_client.add( "foo-n1", 5, "baz-n1" ); // fails
// _client.set( "foo-n1", 5, "bar" ); // would be fine
CASValue<Object> result = _client.gets("foo-n1");
// result.getValue();
}
示例12: gets
import net.spy.memcached.CASValue; //导入依赖的package包/类
public CASValue<Object> gets(Object key) {
CASValue<Object> cas = null;
try {
cas = client.gets(getKey(key));
} catch (RuntimeException e) {
log.warn("OK to ignore, memcached gets threw an exception, unable to read the key:"
+ key);
if (log.isDebugEnabled()) {
log.debug("gets failed for key:" + key, e);
}
}
return cas;
}
示例13: casUpdate
import net.spy.memcached.CASValue; //导入依赖的package包/类
private ComposableFuture<CASResponse> casUpdate(final K key, final EntryMapper<K, V> mapper) {
try {
final String cacheKey = keyTranslator.translateKey(key);
final ComposableFuture<CASValue<V>> getFutureValue = SpyFutureHelper.fromCASValue(() -> {
@SuppressWarnings("unchecked")
final Transcoder<V> transcoder = (Transcoder<V>) spyClient.getTranscoder();
return spyClient.asyncGets(cacheKey, transcoder);
});
return getFutureValue.flatMap(result -> {
final V newValue = result == null ? mapper.map(key, null) : mapper.map(key, result.getValue());
if (newValue == null) {
return fromValue(CASResponse.OBSERVE_ERROR_IN_ARGS);
}
if (result != null) {
return SpyFutureHelper.fromCASResponse(() -> spyClient.asyncCAS(cacheKey, result.getCas(), newValue));
} else {
final ComposableFuture<Boolean> addResponse = SpyFutureHelper.fromOperation(
() -> spyClient.add(cacheKey, expirationSpyUnits, newValue));
return addResponse.map(result1 -> {
if (result1 == Boolean.TRUE) {
return CASResponse.OK;
} else {
return CASResponse.EXISTS;
}
});
}
});
} catch (final Exception e) {
return fromError(e);
}
}
示例14: collectResults
import net.spy.memcached.CASValue; //导入依赖的package包/类
private void collectResults() {
CASValue<Object> casValue = client.gets(key);
final JsonElement el = new JsonParser().parse(casValue.getValue().toString());
final JsonArray elements = el.getAsJsonObject().getAsJsonArray("elements");
Set<Integer> saved = new HashSet<>();
for (int i = 0; i < elements.size(); i++) {
saved.add(elements.get(i).getAsInt());
}
Set<Integer> survivors = new HashSet<>(acknowledgedWrites);
survivors.retainAll(saved);
Set<Integer> lost = new HashSet<>(acknowledgedWrites);
lost.removeAll(survivors);
Set<Integer> unacked = new HashSet<>(saved);
unacked.removeAll(acknowledgedWrites);
log.info(total + " total");
log.info(acknowledgedWrites.size() + " acknowledged");
log.info(survivors.size() + " survivors");
if (!lost.isEmpty()) {
log.info(lost.size() + " acknowledged writes lost!");
log.info(lost);
}
if (!unacked.isEmpty()) {
log.info(unacked.size() + " unacknowledged writes found!");
log.info(unacked);
}
log.info((double) acknowledgedWrites.size() / total + " ack rate");
if (!lost.isEmpty()) {
log.info((double) lost.size() / acknowledgedWrites.size() + " loss rate");
}
// if (!unacked.isEmpty()) {
//this rate doesn't seem correct
// log.info((double)unacked.size() / acknowledgedWrites.size() + " unacknowledged but successful rate" );
// }
}
示例15: findById
import net.spy.memcached.CASValue; //导入依赖的package包/类
private void findById(Message<JsonObject> message) {
String id = getMandatoryString("id", message);
if (id == null) {
sendError(message, "id must be specified");
return;
}
String mode = message.body().getString("mode", "standard");
int exp = message.body().getInteger("expiration", 0);
CASValue<Object> object = null;
if (mode.equals("lock")) {
object = client.getAndLock(id, exp);
}
else if (mode.equals("touch")) {
object = client.getAndTouch(id, exp);
}
else if (mode.equals("standard")) {
object = client.gets(id);
}
if (object != null) {
sendOK(message, new JsonObject((String)object.getValue()));
}
else {
sendError(message, "not found");
}
}