Search in sources :

Example 41 with PropertyStoreException

use of com.linkedin.d2.discovery.stores.PropertyStoreException in project rest.li by linkedin.

the class ZooKeeperPermanentStoreStrawMan method main.

public static void main(String[] args) throws IOException, InterruptedException, PropertyStoreException {
    ZKConnection zkClient = new ZKConnection("localhost:2181", 1000);
    Set<String> listenTos = new HashSet<String>();
    ZooKeeperPermanentStore<String> zk = new ZooKeeperPermanentStore<String>(zkClient, new PropertyStringSerializer(), "/test/lb/test-property");
    listenTos.add("foo12");
    ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
    PropertyEventBus<String> bus = new PropertyEventBusImpl<String>(executorService, zk);
    bus.register(listenTos, new PropertyEventSubscriber<String>() {

        @Override
        public void onAdd(String propertyName, String propertyValue) {
            System.err.println("onAdd: " + propertyName + "\t" + propertyValue);
        }

        @Override
        public void onInitialize(String propertyName, String propertyValue) {
            System.err.println("onInitialize: " + propertyName + "\t" + propertyValue);
        }

        @Override
        public void onRemove(String propertyName) {
            System.err.println("onRemove: " + propertyName);
        }
    });
    zk.put("foo12", "TEST1");
    zk.put("foo12", "TEST2");
    zk.put("foo12", "TEST3");
    zk.put("foo12", "TEST4");
    zk.put("foo12", "TEST5");
    zk.remove("foo12");
    try {
        Thread.sleep(10000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    zkClient.getZooKeeper().close();
    executorService.shutdown();
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) PropertyStringSerializer(com.linkedin.d2.discovery.stores.PropertyStringSerializer) PropertyEventBusImpl(com.linkedin.d2.discovery.event.PropertyEventBusImpl) HashSet(java.util.HashSet)

Example 42 with PropertyStoreException

use of com.linkedin.d2.discovery.stores.PropertyStoreException in project rest.li by linkedin.

the class PropertyStoreTest method testShutdown.

@Test(groups = { "small", "back-end" })
public void testShutdown() throws InterruptedException, PropertyStoreException {
    PropertyStore<String> store = getStore();
    final CountDownLatch latch = new CountDownLatch(1);
    store.shutdown(new PropertyEventShutdownCallback() {

        @Override
        public void done() {
            latch.countDown();
        }
    });
    if (!latch.await(5, TimeUnit.SECONDS)) {
        fail("unable to shut down store");
    }
}
Also used : PropertyEventShutdownCallback(com.linkedin.d2.discovery.event.PropertyEventThread.PropertyEventShutdownCallback) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.testng.annotations.Test)

Example 43 with PropertyStoreException

use of com.linkedin.d2.discovery.stores.PropertyStoreException in project rest.li by linkedin.

the class TestD2Config method verifyServiceProperties.

public static void verifyServiceProperties(String cluster, String service, String path, String serviceGroup, boolean defaultRoutingToMaster) throws IOException, URISyntaxException, PropertyStoreException {
    ServiceProperties serviceprops = getServiceProperties(_zkclient, service, serviceGroup);
    assertEquals(serviceprops.getClusterName(), cluster);
    assertEquals(serviceprops.getServiceName(), service);
    assertEquals(serviceprops.getPath(), path);
    assertEquals(serviceprops.getLoadBalancerStrategyList(), Arrays.asList(new String[] { "degrader", "degraderV3" }));
    assertEquals(serviceprops.getLoadBalancerStrategyProperties().get("maxClusterLatencyWithoutDegrading"), String.valueOf(500));
    assertEquals(serviceprops.getLoadBalancerStrategyProperties().get("updateIntervalsMs"), String.valueOf(5000));
    assertEquals(serviceprops.getLoadBalancerStrategyProperties().get("defaultSuccessfulTransmissionWeight"), String.valueOf(1.0));
    assertEquals(serviceprops.getLoadBalancerStrategyProperties().get("pointsPerWeight"), String.valueOf(100));
    if (defaultRoutingToMaster) {
        String defaultRouting = (String) serviceprops.getServiceMetadataProperties().get(PropertyKeys.DEFAULT_ROUTING_TO_MASTER);
        Assert.assertTrue(Boolean.valueOf(defaultRouting));
    }
}
Also used : ServiceProperties(com.linkedin.d2.balancer.properties.ServiceProperties)

Example 44 with PropertyStoreException

use of com.linkedin.d2.discovery.stores.PropertyStoreException in project rest.li by linkedin.

the class TestD2Config method verifyClusterProperties.

public static void verifyClusterProperties(String cluster) throws IOException, URISyntaxException, PropertyStoreException {
    ClusterProperties clusterprops = getClusterProperties(_zkclient, cluster);
    assertEquals(clusterprops.getClusterName(), cluster);
    assertEquals(clusterprops.getPrioritizedSchemes(), Arrays.asList(new String[] { "http" }));
    assertEquals(clusterprops.getProperties().get("requestTimeout"), String.valueOf(10000));
    assertEquals(clusterprops.getBanned(), new TreeSet<URI>());
}
Also used : ClusterProperties(com.linkedin.d2.balancer.properties.ClusterProperties) URI(java.net.URI)

Aggregations

None (com.linkedin.common.util.None)19 FutureCallback (com.linkedin.common.callback.FutureCallback)18 HashMap (java.util.HashMap)18 UriProperties (com.linkedin.d2.balancer.properties.UriProperties)15 Test (org.testng.annotations.Test)14 PartitionData (com.linkedin.d2.balancer.properties.PartitionData)9 PropertyStoreException (com.linkedin.d2.discovery.stores.PropertyStoreException)9 ServiceProperties (com.linkedin.d2.balancer.properties.ServiceProperties)8 URI (java.net.URI)8 ClusterProperties (com.linkedin.d2.balancer.properties.ClusterProperties)7 ServicePropertiesJsonSerializer (com.linkedin.d2.balancer.properties.ServicePropertiesJsonSerializer)7 UriPropertiesJsonSerializer (com.linkedin.d2.balancer.properties.UriPropertiesJsonSerializer)7 UriPropertiesMerger (com.linkedin.d2.balancer.properties.UriPropertiesMerger)7 IOException (java.io.IOException)7 HashSet (java.util.HashSet)6 PropertyEventBusImpl (com.linkedin.d2.discovery.event.PropertyEventBusImpl)5 ZooKeeperEphemeralStore (com.linkedin.d2.discovery.stores.zk.ZooKeeperEphemeralStore)5 ExecutionException (java.util.concurrent.ExecutionException)5 ClusterPropertiesJsonSerializer (com.linkedin.d2.balancer.properties.ClusterPropertiesJsonSerializer)4 PropertyStringSerializer (com.linkedin.d2.discovery.stores.PropertyStringSerializer)4