Search in sources :

Example 1 with CachedData

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;
        }
    };
}
Also used : CachedData(net.spy.memcached.CachedData) Future(java.util.concurrent.Future) OperationFuture(net.spy.memcached.internal.OperationFuture) BulkFuture(net.spy.memcached.internal.BulkFuture) TimeUnit(java.util.concurrent.TimeUnit)

Example 2 with CachedData

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();
        }
    };
}
Also used : CachedData(net.spy.memcached.CachedData) TimeUnit(java.util.concurrent.TimeUnit) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) BulkGetCompletionListener(net.spy.memcached.internal.BulkGetCompletionListener) BulkFuture(net.spy.memcached.internal.BulkFuture)

Example 3 with CachedData

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);
}
Also used : DefaultAuthenticationBuilder(org.apereo.cas.authentication.DefaultAuthenticationBuilder) UsernamePasswordCredential(org.apereo.cas.authentication.UsernamePasswordCredential) Credential(org.apereo.cas.authentication.Credential) HttpBasedServiceCredential(org.apereo.cas.authentication.HttpBasedServiceCredential) DefaultAuthenticationBuilder(org.apereo.cas.authentication.DefaultAuthenticationBuilder) AuthenticationBuilder(org.apereo.cas.authentication.AuthenticationBuilder) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) DefaultPrincipalFactory(org.apereo.cas.authentication.principal.DefaultPrincipalFactory) MockServiceTicket(org.apereo.cas.mock.MockServiceTicket) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) CachedData(net.spy.memcached.CachedData) NeverExpiresExpirationPolicy(org.apereo.cas.ticket.support.NeverExpiresExpirationPolicy) TicketGrantingTicketImpl(org.apereo.cas.ticket.TicketGrantingTicketImpl) AcceptUsersAuthenticationHandler(org.apereo.cas.authentication.AcceptUsersAuthenticationHandler) DefaultHandlerResult(org.apereo.cas.authentication.DefaultHandlerResult) UsernamePasswordCredential(org.apereo.cas.authentication.UsernamePasswordCredential) BasicCredentialMetaData(org.apereo.cas.authentication.BasicCredentialMetaData) Test(org.junit.Test)

Example 4 with CachedData

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);
    }
}
Also used : CachedData(net.spy.memcached.CachedData) Output(com.esotericsoftware.kryo.io.Output) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 5 with CachedData

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));
}
Also used : MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) CachedData(net.spy.memcached.CachedData) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket)

Aggregations

CachedData (net.spy.memcached.CachedData)9 TimeUnit (java.util.concurrent.TimeUnit)4 BulkFuture (net.spy.memcached.internal.BulkFuture)4 Output (com.esotericsoftware.kryo.io.Output)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 Future (java.util.concurrent.Future)2 lombok.val (lombok.val)2 BulkGetCompletionListener (net.spy.memcached.internal.BulkGetCompletionListener)2 OperationFuture (net.spy.memcached.internal.OperationFuture)2 MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)2 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)2 KryoException (com.esotericsoftware.kryo.KryoException)1 LinkedHashMap (java.util.LinkedHashMap)1 AcceptUsersAuthenticationHandler (org.apereo.cas.authentication.AcceptUsersAuthenticationHandler)1 AuthenticationBuilder (org.apereo.cas.authentication.AuthenticationBuilder)1 BasicCredentialMetaData (org.apereo.cas.authentication.BasicCredentialMetaData)1