// set up state
_state.listenToService("service-1", new NullStateListenerCallback());
_state.listenToCluster("cluster-1", new NullStateListenerCallback());
_state.setDelayedExecution(0);
_serviceRegistry.put("service-1", new ServiceProperties("service-1",
"cluster-1",
"/test",
"random",
null,
Collections.<String, Object>emptyMap(),
Collections.<String, Object>emptyMap(),
Collections.<String, String>emptyMap(),
schemes,
Collections.<URI>emptySet()));
_clusterRegistry.put("cluster-1", new ClusterProperties("cluster-1"));
_uriRegistry.put("cluster-1", new UriProperties("cluster-1", uriData));
URI uri1 = URI.create("http://partition-cluster-1/test1");
URI uri2 = URI.create("http://partition-cluster-1/test2");
_state.listenToCluster("partition-cluster-1", new NullStateListenerCallback());
_clusterRegistry.put("partition-cluster-1", new ClusterProperties("partition-cluster-1", null,
new HashMap<String, String>(), new HashSet<URI>(), new RangeBasedPartitionProperties("id=(\\d+)", 0, 100, 2)));
_state.listenToService("partition-service-1", new NullStateListenerCallback());
_serviceRegistry.put("partition-service-1",
new ServiceProperties("partition-service-1",
"partition-cluster-1", "/partition-test", "degraderV3", null, Collections.<String, Object>emptyMap(),
Collections.<String, Object>emptyMap(),
Collections.<String, String>emptyMap(),
schemes,
Collections.<URI>emptySet()));
Map<Integer, PartitionData> partitionWeight = new HashMap<Integer, PartitionData>();
partitionWeight.put(0, new PartitionData(1d));
partitionWeight.put(1, new PartitionData(2d));
Map<URI, Map<Integer, PartitionData>> partitionDesc =
new HashMap<URI, Map<Integer, PartitionData>>();
partitionDesc.put(uri1, partitionWeight);
partitionWeight.remove(0);
partitionWeight.put(2, new PartitionData(1d));
partitionDesc.put(uri2, partitionWeight);
_uriRegistry.put("partition-cluster-1", new UriProperties("partition-cluster-1", partitionDesc));
TrackerClient client1 = _state.getClient("partition-service-1", uri1);
TrackerClient client2 = _state.getClient("partition-service-1", uri2);
assertEquals(client2.getPartitionWeight(1), 2d);
assertEquals(client2.getPartitionWeight(2), 1d);
assertEquals(client1.getPartitionWeight(1), 2d);
// Get client, then refresh cluster
TrackerClient client = _state.getClient("service-1", uri);
client.restRequest(new RestRequestBuilder(URI.create("d2://service-1/foo")).build(),
new RequestContext(),
Collections.<String, String>emptyMap(),
new TransportCallbackAdapter<RestResponse>(Callbacks.<RestResponse>empty()));
// now force a refresh by adding cluster
_clusterRegistry.put("cluster-1", new ClusterProperties("cluster-1"));
// Get client, then refresh service
client = _state.getClient("service-1", uri);
client.restRequest(new RestRequestBuilder(URI.create("d2://service-1/foo")).build(),
new RequestContext(),
Collections.<String, String>emptyMap(),
new TransportCallbackAdapter<RestResponse>(Callbacks.<RestResponse>empty()));
// refresh by adding service
_serviceRegistry.put("service-1", new ServiceProperties("service-1",
"cluster-1",
"/test",
"random",
Collections.<String>emptyList(),
Collections.<String, Object>emptyMap(),