use of net.spy.memcached.CachedData in project druid by druid-io.
the class MockMemcachedClient method asyncGet.
@Override
public <T> Future<T> asyncGet(String key, final Transcoder<T> tc) {
CachedData data = theMap.get(key);
final T theValue = data != null ? tc.decode(data) : null;
return new Future<T>() {
@Override
public boolean cancel(boolean b) {
return false;
}
@Override
public boolean isCancelled() {
return false;
}
@Override
public boolean isDone() {
return true;
}
@Override
public T get() throws InterruptedException, ExecutionException {
return theValue;
}
@Override
public T get(long l, TimeUnit timeUnit) throws InterruptedException, ExecutionException, TimeoutException {
return theValue;
}
};
}
use of net.spy.memcached.CachedData in project druid by druid-io.
the class MockMemcachedClient method asyncGetBulk.
@Override
public <T> BulkFuture<Map<String, T>> asyncGetBulk(final Iterator<String> keys, final Transcoder<T> tc) {
return new BulkFuture<Map<String, T>>() {
@Override
public boolean isTimeout() {
return false;
}
@Override
public Map<String, T> getSome(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException {
return get();
}
@Override
public OperationStatus getStatus() {
return null;
}
@Override
public Future<Map<String, T>> addListener(BulkGetCompletionListener bulkGetCompletionListener) {
return null;
}
@Override
public Future<Map<String, T>> removeListener(BulkGetCompletionListener bulkGetCompletionListener) {
return null;
}
@Override
public boolean cancel(boolean b) {
return false;
}
@Override
public boolean isCancelled() {
return false;
}
@Override
public boolean isDone() {
return true;
}
@Override
public Map<String, T> get() throws InterruptedException, ExecutionException {
Map<String, T> retVal = Maps.newHashMap();
while (keys.hasNext()) {
String key = keys.next();
CachedData data = theMap.get(key);
retVal.put(key, data != null ? tc.decode(data) : null);
}
return retVal;
}
@Override
public Map<String, T> get(long l, TimeUnit timeUnit) throws InterruptedException, ExecutionException, TimeoutException {
return get();
}
};
}
use of net.spy.memcached.CachedData in project cas by apereo.
the class KryoTranscoderTests method verifyEncodeDecodeTGTImpl.
@Test
public void verifyEncodeDecodeTGTImpl() throws Exception {
final Credential userPassCredential = new UsernamePasswordCredential(USERNAME, PASSWORD);
final AuthenticationBuilder bldr = new DefaultAuthenticationBuilder(new DefaultPrincipalFactory().createPrincipal("user", new HashMap<>(this.principalAttributes)));
bldr.setAttributes(new HashMap<>(this.principalAttributes));
bldr.setAuthenticationDate(ZonedDateTime.now());
bldr.addCredential(new BasicCredentialMetaData(userPassCredential));
bldr.addFailure("error", AccountNotFoundException.class);
bldr.addSuccess("authn", new DefaultHandlerResult(new AcceptUsersAuthenticationHandler(""), new BasicCredentialMetaData(userPassCredential)));
final TicketGrantingTicket expectedTGT = new TicketGrantingTicketImpl(TGT_ID, RegisteredServiceTestUtils.getService(), null, bldr.build(), new NeverExpiresExpirationPolicy());
final ServiceTicket ticket = expectedTGT.grantServiceTicket(ST_ID, RegisteredServiceTestUtils.getService(), new NeverExpiresExpirationPolicy(), false, true);
CachedData result = transcoder.encode(expectedTGT);
final TicketGrantingTicket resultTicket = (TicketGrantingTicket) transcoder.decode(result);
assertEquals(expectedTGT, resultTicket);
result = transcoder.encode(ticket);
final ServiceTicket resultStTicket = (ServiceTicket) transcoder.decode(result);
assertEquals(ticket, resultStTicket);
}
use of net.spy.memcached.CachedData in project cas by apereo.
the class KryoTranscoder method encode.
@Override
public CachedData encode(final Object obj) {
final ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
try (Output output = new Output(byteStream)) {
this.kryo.writeClassAndObject(output, obj);
output.flush();
final byte[] bytes = byteStream.toByteArray();
return new CachedData(0, bytes, bytes.length);
}
}
use of net.spy.memcached.CachedData in project cas by apereo.
the class CasKryoTranscoderTests method internalProxyTest.
private void internalProxyTest(final String proxyUrl) {
final TicketGrantingTicket expectedTGT = new MockTicketGrantingTicket(USERNAME);
expectedTGT.grantServiceTicket(ST_ID, null, null, false, true);
final CachedData result = transcoder.encode(expectedTGT);
assertEquals(expectedTGT, transcoder.decode(result));
assertEquals(expectedTGT, transcoder.decode(result));
}
Aggregations