Refine search
@Override public boolean evictBlock(BlockCacheKey cacheKey) { try { cacheStats.evict(); return client.delete(cacheKey.toString()).get(); } catch (InterruptedException e) { LOG.warn("Error deleting " + cacheKey.toString(), e); Thread.currentThread().interrupt(); } catch (ExecutionException e) { if (LOG.isDebugEnabled()) { LOG.debug("Error deleting " + cacheKey.toString(), e); } } return false; }
public <T> OperationFuture<Boolean> touch(final String key, final int exp, EVCacheLatch evcacheLatch) { final CountDownLatch latch = new CountDownLatch(1); final OperationFuture<Boolean> rv = new OperationFuture<Boolean>(key, latch, connectionFactory.getOperationTimeout(), executorService); final Stopwatch operationDuration = getTimer(TOUCH_OPERATION_STRING).start(); Operation op = opFact.touch(key, exp, new OperationCallback() { rv.setOperation(op); if (evcacheLatch != null && evcacheLatch instanceof EVCacheLatchImpl && !client.isInWriteOnly()) ((EVCacheLatchImpl) evcacheLatch).addFuture(rv); mconn.enqueueOperation(key, op);
/** * Wrapper method that either inspects the future or not. * * @param future the future to potentially verify. * @return the status of the future result. */ private Status checkFutureStatus(final OperationFuture<?> future) { if (checkFutures) { return future.getStatus().isSuccess() ? Status.OK : Status.ERROR; } else { return Status.OK; } }
if(appendSuccess) { operationDuration.stop(); latch.countDown(); rv.signalComplete(); } else { Operation op = opFact.store(StoreType.add, key, co.getFlags(), exp, co.getData(), new StoreOperation.Callback() { rv.setOperation(op); mconn.enqueueOperation(key, op);
if (log.isDebugEnabled()) log.debug(";App : " + evcacheEvent.getAppName() + "; Call : " + evcacheEvent.getCall() + "; Keys : " + evcacheEvent.getCanonicalKeys() + "; completeCount : " + completeCount + "; totalFutureCount : " + totalFutureCount +"; failureCount : " + failureCount); try { if(future.isDone() && future.get().equals(Boolean.FALSE)) { failureCount++;
public T get(long duration, TimeUnit units) throws InterruptedException, TimeoutException, ExecutionException { if(!latch.await(duration, units)) { throw new CheckedOperationTimeoutException( "Timed out waiting for operation", op); } if(op != null && op.hasErrored()) { throw new ExecutionException(op.getException()); } if(isCancelled()) { throw new ExecutionException(new RuntimeException("Cancelled")); } return objRef.get(); }
private Future<Long> asyncMutate(Mutator m, String key, int by, long def, int exp) { final CountDownLatch latch = new CountDownLatch(1); final OperationFuture<Long> rv = new OperationFuture<Long>( latch, operationTimeout); Operation op = addOp(key, opFact.mutate(m, key, by, def, exp, new OperationCallback() { public void receivedStatus(OperationStatus s) { rv.set(new Long(s.isSuccess() ? s.getMessage() : "-1")); } public void complete() { latch.countDown(); } })); rv.setOperation(op); return rv; }
casr = (CASResponse) future.get(); observeFuture.set(casr, future.getStatus()); if (future.getCas() != null) { observeFuture.setCas(future.getCas()); latch.countDown(); observeFuture.signalComplete(); return; observePoll(key, future.getCas(), req, rep, false); observeFuture.set(casr, future.getStatus()); } catch (ObservedException e) { observeFuture.set(CASResponse.OBSERVE_ERROR_IN_ARGS, latch.countDown(); observeFuture.signalComplete();
public <T> OperationFuture<Boolean> asyncAppendOrAdd(final String key, int exp, CachedData co, EVCacheLatch evcacheLatch) { final CountDownLatch latch = new CountDownLatch(1); final OperationFuture<Boolean> rv = new EVCacheOperationFuture<Boolean>(key, latch, new AtomicReference<Boolean>(null), connectionFactory.getOperationTimeout(), executorService, appName, serverGroup); final Stopwatch operationDuration = getTimer(AOA_STRING).start(); rv.setOperation(op); mconn.enqueueOperation(key, op); if (evcacheLatch != null && evcacheLatch instanceof EVCacheLatchImpl && !client.isInWriteOnly()) ((EVCacheLatchImpl) evcacheLatch).addFuture(rv);
public void testMemcachedCodec() throws Exception { Cache<byte[], byte[]> cache = cacheManager.getCache(MEMCACHED_CACHE); memcachedClient.set("k1", 3600, "v1").get(); assertTrue(cache.containsKey("k1".getBytes())); String sessionId = interpreter.createSessionId(MEMCACHED_CACHE); Map<String, String> response = interpreter.execute(sessionId, "get --codec=memcached k1;"); assertEquals("v1", response.get(ResultKeys.OUTPUT.toString())); interpreter.execute(sessionId, "put --codec=memcached k2 v2;"); String v2 = (String) memcachedClient.get("k2"); assertEquals("v2", v2); }
/** * Test for issue #105: Make memcached node optional for single-node setup * http://code.google.com/p/memcached-session-manager/issues/detail?id=105 */ @Test public void testBackupSessionFailureWithoutMemcachedNodeIdConfigured105() throws Exception { _service.setMemcachedNodes( "127.0.0.1:11211" ); _service.setSessionBackupAsync(false); _service.startInternal(new MemcachedStorageClient(_memcachedMock)); final MemcachedBackupSession session = createSession( _service ); session.access(); session.endAccess(); session.setAttribute( "foo", "bar" ); @SuppressWarnings( "unchecked" ) final OperationFuture<Boolean> futureMock = mock( OperationFuture.class ); when( futureMock.get( ) ).thenThrow(new ExecutionException(new RuntimeException("Simulated exception."))); when( futureMock.get( anyInt(), any( TimeUnit.class ) ) ).thenThrow(new ExecutionException(new RuntimeException("Simulated exception."))); when( _memcachedMock.set( eq( session.getId() ), anyInt(), any(), any( Transcoder.class ) ) ).thenReturn( futureMock ); final BackupResult backupResult = _service.backupSession( session.getIdInternal(), false, null ).get(); assertEquals(backupResult.getStatus(), BackupResultStatus.FAILURE); verify( _memcachedMock, times( 1 ) ).set( eq( session.getId() ), anyInt(), any(), any( Transcoder.class ) ); }
when( _memcachedMock.get( eq( validityKey ), any ( Transcoder.class) ) ).thenReturn( validityData ); when( futureMock.get() ).thenReturn( Boolean.FALSE ); when( futureMock.get( anyInt(), any( TimeUnit.class ) ) ).thenReturn( Boolean.FALSE ); when( _memcachedMock.add( any( String.class ), anyInt(), any(), any( Transcoder.class ) ) ).thenReturn( futureMock ); verify( _memcachedMock, times( 1 ) ).set( eq( validityKey ), eq( 0 ), any(), any( Transcoder.class ) );
@SuppressWarnings("unchecked") @BeforeMethod public void setup() throws Exception { final StandardContext context = createContext(); context.setBackgroundProcessorDelay( 1 ); // needed for test of updateExpiration final SessionManager manager = createSessionManager(context); _service = manager.getMemcachedSessionService(); _service.setMemcachedNodes( "n1:127.0.0.1:11211" ); _service.setSessionBackupAsync( false ); _service.setSticky( true ); _memcachedMock = mock( MemcachedClient.class ); final OperationFuture<Boolean> setResultMock = mock( OperationFuture.class ); when( setResultMock.get( ) ).thenReturn( Boolean.TRUE ); when( setResultMock.get( anyInt(), any( TimeUnit.class ) ) ).thenReturn( Boolean.TRUE ); when( _memcachedMock.set( any( String.class ), anyInt(), any(), any( Transcoder.class ) ) ).thenReturn( setResultMock ); final OperationFuture<Boolean> deleteResultMock = mock( OperationFuture.class ); when( deleteResultMock.get() ).thenReturn( Boolean.TRUE ); when( _memcachedMock.delete( anyString() ) ).thenReturn( deleteResultMock ); startInternal( manager, _memcachedMock ); _executor = Executors.newCachedThreadPool(); }
switch (writeMode) { case set: future = client.set(key, expireTime, value); break; case add: future = client.add(key, expireTime, value); break; case replace: future = client.replace(key, expireTime, value); break; if (future == null || future.getStatus() == null || !future.getStatus().isSuccess()) { throw DataXException.asDataXException(OcsWriterErrorCode.COMMIT_FAILED, "提交数据到ocs失败");
when(addResultMock.get()).thenReturn(true); when(addResultMock.get(anyLong(), any(TimeUnit.class))).thenReturn(true); when(_memcachedMock.add(anyString(), anyInt(), any(), any(Transcoder.class))).thenReturn(addResultMock); _service.getTrackingHostValve().storeRequestThreadLocal(requestMock); when(_memcachedMock.get(eq(session.getId()), any(Transcoder.class))).thenReturn(transcoderService.serialize(session));
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); }
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()); }
@Override public boolean add(final String key, int exp, final Object value) { log.trace("Memcached add operation on key '{}', with value:{}", key, value); boolean success = false; int tryCount = 0; do { try { if (tryCount > 0) { Thread.sleep(retryAfterSec * 1000); log.warn("retrying operation #{}", tryCount); } tryCount++; success = memcachedClient.add(key, exp, value) .get(); } catch (final Exception e) { log.warn("memcache set: {}", e.getMessage()); } } while (!success && tryCount < maxTry); if (!success) { log.error("Failed to add key to Elasticache {}", key); } if (success && tryCount > 1) { log.info("Connection restored OK to Elasticache cluster"); } available = success; return success; }
public void testStats() throws Exception { MemcachedClient client = bootstrapClient(); Map stats = client.getStats(); logger.info("stats:"+stats+" val:"+stats.values().toArray()[0]); assertEquals(1, stats.size()); assertTrue(((Map)stats.values().toArray()[0]).isEmpty()); assertTrue(client.add("keystats", 1, "stats").get()); }
@Override public Boolean get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { for (OperationFuture<Boolean> future : futures) { if (future.get(timeout, unit) == false) return false; } return true; }