Search in sources :

Example 71 with FutureCallback

use of com.linkedin.common.callback.FutureCallback in project rest.li by linkedin.

the class ZKFSTest method testClientFactoryProvider.

@Test
public void testClientFactoryProvider() throws Exception {
    startServer();
    try {
        ZKFSLoadBalancer balancer = getBalancer();
        FutureCallback<None> callback = new FutureCallback<None>();
        balancer.start(callback);
        callback.get(30, TimeUnit.SECONDS);
        Facilities facilities = balancer.getFacilities();
        TransportClientFactory factory = facilities.getClientFactory("http");
        Assert.assertNotNull(factory);
        Assert.assertTrue(factory instanceof HttpClientFactory);
    } finally {
        stopServer();
    }
}
Also used : None(com.linkedin.common.util.None) TransportClientFactory(com.linkedin.r2.transport.common.TransportClientFactory) HttpClientFactory(com.linkedin.r2.transport.http.client.HttpClientFactory) FutureCallback(com.linkedin.common.callback.FutureCallback) Facilities(com.linkedin.d2.balancer.Facilities) Test(org.testng.annotations.Test)

Example 72 with FutureCallback

use of com.linkedin.common.callback.FutureCallback in project rest.li by linkedin.

the class ZooKeeperEphemeralStorePublisherTest method getStore.

@Override
protected ZooKeeperStore<String> getStore() {
    ZooKeeperEphemeralStore<String> store = new ZooKeeperEphemeralStore<String>(getConnection(), new PropertyStringSerializer(), _merger, "/testing/testPath", false, true);
    try {
        FutureCallback<None> callback = new FutureCallback<None>();
        store.start(callback);
        callback.get(30, TimeUnit.SECONDS);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return store;
}
Also used : ZooKeeperEphemeralStore(com.linkedin.d2.discovery.stores.zk.ZooKeeperEphemeralStore) None(com.linkedin.common.util.None) PropertyStringSerializer(com.linkedin.d2.discovery.stores.PropertyStringSerializer) FutureCallback(com.linkedin.common.callback.FutureCallback) TimeoutException(java.util.concurrent.TimeoutException) PropertyStoreException(com.linkedin.d2.discovery.stores.PropertyStoreException)

Example 73 with FutureCallback

use of com.linkedin.common.callback.FutureCallback in project rest.li by linkedin.

the class ZooKeeperChildrenDataPublisherTest method testChildDataChanged.

@Test
public void testChildDataChanged() throws IOException, InterruptedException, ExecutionException {
    ZKConnection client = new ZKConnection("localhost:" + _port, 5000);
    client.start();
    final ZooKeeperChildrenDataPublisher<Map<String, String>, String> publisher = new ZooKeeperChildrenDataPublisher<Map<String, String>, String>(client, new PropertyStringSerializer(), "/");
    final CountDownLatch initLatch = new CountDownLatch(1);
    final CountDownLatch addLatch = new CountDownLatch(1);
    final CountDownLatch startLatch = new CountDownLatch(1);
    final PropertyEventSubscriber<Map<String, String>> subscriber = new PropertyEventSubscriber<Map<String, String>>() {

        @Override
        public void onInitialize(String propertyName, Map<String, String> propertyValue) {
            initLatch.countDown();
        }

        @Override
        public void onAdd(String propertyName, Map<String, String> propertyValue) {
            _outputData = propertyValue;
            addLatch.countDown();
        }

        @Override
        public void onRemove(String propertyName) {
        }
    };
    publisher.start(new Callback<None>() {

        @Override
        public void onError(Throwable e) {
        }

        @Override
        public void onSuccess(None result) {
            _eventBus = new PropertyEventBusImpl<Map<String, String>>(_executor, publisher);
            _eventBus.register(Collections.singleton("bucket"), subscriber);
            startLatch.countDown();
        }
    });
    if (!startLatch.await(60, TimeUnit.SECONDS)) {
        Assert.fail("unable to start ZookeeperChildrenDataPublisher");
    }
    if (!initLatch.await(60, TimeUnit.SECONDS)) {
        Assert.fail("unable to publish initial property value");
    }
    FutureCallback<None> callback = new FutureCallback<None>();
    _zkClient.setDataUnsafe("/bucket/child-1", "4".getBytes(), callback);
    callback.get();
    if (!addLatch.await(60, TimeUnit.SECONDS)) {
        Assert.fail("unable to get publish initialized property value");
    }
    _testData.put("bucket/child-1", "4");
    assertEquals(_outputData, _testData);
    _eventBus.unregister(Collections.singleton("bucket"), subscriber);
    client.shutdown();
}
Also used : PropertyEventSubscriber(com.linkedin.d2.discovery.event.PropertyEventSubscriber) CountDownLatch(java.util.concurrent.CountDownLatch) PropertyEventBusImpl(com.linkedin.d2.discovery.event.PropertyEventBusImpl) HashMap(java.util.HashMap) Map(java.util.Map) None(com.linkedin.common.util.None) FutureCallback(com.linkedin.common.callback.FutureCallback) Test(org.testng.annotations.Test)

Example 74 with FutureCallback

use of com.linkedin.common.callback.FutureCallback in project rest.li by linkedin.

the class ZooKeeperChildrenDataPublisherTest method testChildDeletion.

@Test
public void testChildDeletion() throws IOException, InterruptedException, ExecutionException {
    ZKConnection client = new ZKConnection("localhost:" + _port, 5000);
    client.start();
    final ZooKeeperChildrenDataPublisher<Map<String, String>, String> publisher = new ZooKeeperChildrenDataPublisher<Map<String, String>, String>(client, new PropertyStringSerializer(), "/");
    final CountDownLatch initLatch = new CountDownLatch(1);
    final CountDownLatch addLatch = new CountDownLatch(1);
    final CountDownLatch startLatch = new CountDownLatch(1);
    final PropertyEventSubscriber<Map<String, String>> subscriber = new PropertyEventSubscriber<Map<String, String>>() {

        @Override
        public void onInitialize(String propertyName, Map<String, String> propertyValue) {
            initLatch.countDown();
        }

        @Override
        public void onAdd(String propertyName, Map<String, String> propertyValue) {
            _outputData = propertyValue;
            addLatch.countDown();
        }

        @Override
        public void onRemove(String propertyName) {
        }
    };
    publisher.start(new Callback<None>() {

        @Override
        public void onError(Throwable e) {
        }

        @Override
        public void onSuccess(None result) {
            _eventBus = new PropertyEventBusImpl<Map<String, String>>(_executor, publisher);
            _eventBus.register(Collections.singleton("bucket"), subscriber);
            startLatch.countDown();
        }
    });
    if (!startLatch.await(60, TimeUnit.SECONDS)) {
        Assert.fail("unable to start ZookeeperChildrenDataPublisher");
    }
    if (!initLatch.await(60, TimeUnit.SECONDS)) {
        Assert.fail("unable to publish initial property value");
    }
    FutureCallback<None> callback = new FutureCallback<None>();
    _zkClient.removeNodeUnsafe("/bucket/child-1", callback);
    callback.get();
    if (!addLatch.await(60, TimeUnit.SECONDS)) {
        Assert.fail("unable to get publish initialized property value");
    }
    _testData.remove("bucket/child-1");
    assertEquals(_outputData, _testData);
    _eventBus.unregister(Collections.singleton("bucket"), subscriber);
    client.shutdown();
}
Also used : PropertyEventSubscriber(com.linkedin.d2.discovery.event.PropertyEventSubscriber) CountDownLatch(java.util.concurrent.CountDownLatch) PropertyEventBusImpl(com.linkedin.d2.discovery.event.PropertyEventBusImpl) HashMap(java.util.HashMap) Map(java.util.Map) None(com.linkedin.common.util.None) FutureCallback(com.linkedin.common.callback.FutureCallback) Test(org.testng.annotations.Test)

Example 75 with FutureCallback

use of com.linkedin.common.callback.FutureCallback in project rest.li by linkedin.

the class ZooKeeperPermanentStoreTest method getStore.

@Override
public PropertyStore<String> getStore() throws PropertyStoreException {
    try {
        ZKConnection client = new ZKConnection("localhost:" + PORT, 30000);
        client.start();
        ZooKeeperPermanentStore<String> store = new ZooKeeperPermanentStore<String>(client, new PropertyStringSerializer(), "/test-path");
        FutureCallback<None> callback = new FutureCallback<None>();
        store.start(callback);
        callback.get();
        return store;
    } catch (Exception e) {
        throw new PropertyStoreException(e);
    }
}
Also used : PropertyStoreException(com.linkedin.d2.discovery.stores.PropertyStoreException) None(com.linkedin.common.util.None) PropertyStringSerializer(com.linkedin.d2.discovery.stores.PropertyStringSerializer) FutureCallback(com.linkedin.common.callback.FutureCallback) IOException(java.io.IOException) PropertyStoreException(com.linkedin.d2.discovery.stores.PropertyStoreException)

Aggregations

FutureCallback (com.linkedin.common.callback.FutureCallback)152 Test (org.testng.annotations.Test)116 None (com.linkedin.common.util.None)77 RestRequest (com.linkedin.r2.message.rest.RestRequest)50 ExecutionException (java.util.concurrent.ExecutionException)50 RequestContext (com.linkedin.r2.message.RequestContext)47 RestResponse (com.linkedin.r2.message.rest.RestResponse)43 RestRequestBuilder (com.linkedin.r2.message.rest.RestRequestBuilder)36 HashMap (java.util.HashMap)26 CountDownLatch (java.util.concurrent.CountDownLatch)25 TransportCallbackAdapter (com.linkedin.r2.transport.common.bridge.client.TransportCallbackAdapter)22 ByteString (com.linkedin.data.ByteString)21 RemoteInvocationException (com.linkedin.r2.RemoteInvocationException)21 URI (java.net.URI)21 TimeoutException (java.util.concurrent.TimeoutException)21 StreamResponse (com.linkedin.r2.message.stream.StreamResponse)20 UriProperties (com.linkedin.d2.balancer.properties.UriProperties)16 ArrayList (java.util.ArrayList)16 RestException (com.linkedin.r2.message.rest.RestException)15 AsyncSharedPoolImpl (com.linkedin.r2.transport.http.client.AsyncSharedPoolImpl)14