use of com.twitter.distributedlog.client.resolver.DefaultRegionResolver in project distributedlog by twitter.
the class TestProxyClientManager method createProxyClientManager.
private static ProxyClientManager createProxyClientManager(ProxyClient.Builder builder, HostProvider hostProvider, long periodicHandshakeIntervalMs) {
ClientConfig clientConfig = new ClientConfig();
clientConfig.setPeriodicHandshakeIntervalMs(periodicHandshakeIntervalMs);
clientConfig.setPeriodicOwnershipSyncIntervalMs(-1);
HashedWheelTimer dlTimer = new HashedWheelTimer(new ThreadFactoryBuilder().setNameFormat("TestProxyClientManager-timer-%d").build(), clientConfig.getRedirectBackoffStartMs(), TimeUnit.MILLISECONDS);
return new ProxyClientManager(clientConfig, builder, dlTimer, hostProvider, new ClientStats(NullStatsReceiver.get(), false, new DefaultRegionResolver()));
}
use of com.twitter.distributedlog.client.resolver.DefaultRegionResolver in project distributedlog by twitter.
the class TestConsistentHashRoutingService method testBlackoutHost.
@Test(timeout = 60000)
public void testBlackoutHost() throws Exception {
TestName name = new TestName();
RoutingService routingService = ConsistentHashRoutingService.newBuilder().serverSet(new NameServerSet(name)).resolveFromName(true).numReplicas(997).blackoutSeconds(2).build();
InetSocketAddress inetAddress = new InetSocketAddress("127.0.0.1", 3181);
Address address = Addresses.newInetAddress(inetAddress);
List<Address> addresses = new ArrayList<Address>(1);
addresses.add(address);
name.changeAddrs(addresses);
routingService.startService();
RoutingService.RoutingContext routingContext = RoutingService.RoutingContext.of(new DefaultRegionResolver());
String streamName = "test-blackout-host";
assertEquals(inetAddress, routingService.getHost(streamName, routingContext));
routingService.removeHost(inetAddress, new ChannelWriteException(new IOException("test exception")));
try {
routingService.getHost(streamName, routingContext);
fail("Should fail to get host since no brokers are available");
} catch (NoBrokersAvailableException nbae) {
// expected
}
TimeUnit.SECONDS.sleep(3);
assertEquals(inetAddress, routingService.getHost(streamName, routingContext));
routingService.stopService();
}
use of com.twitter.distributedlog.client.resolver.DefaultRegionResolver in project distributedlog by twitter.
the class TestRegionsRoutingService method testRoutingListener.
@Test(timeout = 60000)
public void testRoutingListener() throws Exception {
int numRoutingServices = 5;
RoutingService.Builder[] routingServiceBuilders = new RoutingService.Builder[numRoutingServices];
Set<SocketAddress> hosts = new HashSet<SocketAddress>();
Map<SocketAddress, String> regionMap = new HashMap<SocketAddress, String>();
for (int i = 0; i < numRoutingServices; i++) {
String finagleNameStr = "inet!127.0.0.1:" + (3181 + i);
routingServiceBuilders[i] = RoutingUtils.buildRoutingService(finagleNameStr);
SocketAddress address = new InetSocketAddress("127.0.0.1", 3181 + i);
hosts.add(address);
regionMap.put(address, "region-" + i);
}
final CountDownLatch doneLatch = new CountDownLatch(numRoutingServices);
final AtomicInteger numHostsLeft = new AtomicInteger(0);
final Set<SocketAddress> jointHosts = new HashSet<SocketAddress>();
RegionsRoutingService regionsRoutingService = RegionsRoutingService.newBuilder().routingServiceBuilders(routingServiceBuilders).resolver(new DefaultRegionResolver(regionMap)).build();
regionsRoutingService.registerListener(new RoutingService.RoutingListener() {
@Override
public void onServerLeft(SocketAddress address) {
numHostsLeft.incrementAndGet();
}
@Override
public void onServerJoin(SocketAddress address) {
jointHosts.add(address);
doneLatch.countDown();
}
});
regionsRoutingService.startService();
doneLatch.await();
assertEquals(numRoutingServices, jointHosts.size());
assertEquals(0, numHostsLeft.get());
assertTrue(Sets.difference(hosts, jointHosts).immutableCopy().isEmpty());
}
use of com.twitter.distributedlog.client.resolver.DefaultRegionResolver in project distributedlog by twitter.
the class TestRoutingService method testRoutingServiceHelper.
private void testRoutingServiceHelper(boolean consistentHash, boolean weightedAddresses, boolean asyncResolution) throws Exception {
ExecutorService executorService = null;
final List<Address> addresses = getAddresses(weightedAddresses);
final TestName name = new TestName();
RoutingService routingService;
if (consistentHash) {
routingService = ConsistentHashRoutingService.newBuilder().serverSet(new NameServerSet(name)).resolveFromName(true).numReplicas(997).build();
} else {
routingService = ServerSetRoutingService.newServerSetRoutingServiceBuilder().serverSetWatcher(new TwitterServerSetWatcher(new NameServerSet(name), true)).build();
}
if (asyncResolution) {
executorService = Executors.newSingleThreadExecutor();
executorService.submit(new Runnable() {
@Override
public void run() {
name.changeAddrs(addresses);
}
});
} else {
name.changeAddrs(addresses);
}
routingService.startService();
HashSet<SocketAddress> mapping = new HashSet<SocketAddress>();
for (int i = 0; i < 1000; i++) {
for (int j = 0; j < 5; j++) {
String stream = "TestStream-" + i + "-" + j;
mapping.add(routingService.getHost(stream, RoutingService.RoutingContext.of(new DefaultRegionResolver())));
}
}
assert (mapping.size() == addresses.size());
if (null != executorService) {
executorService.shutdown();
}
}
use of com.twitter.distributedlog.client.resolver.DefaultRegionResolver in project distributedlog by twitter.
the class TestRegionsRoutingService method testGetHost.
@Test(timeout = 60000)
public void testGetHost() throws Exception {
int numRoutingServices = 3;
RoutingService.Builder[] routingServiceBuilders = new RoutingService.Builder[numRoutingServices];
Map<SocketAddress, String> regionMap = new HashMap<SocketAddress, String>();
for (int i = 0; i < numRoutingServices; i++) {
String finagleNameStr = "inet!127.0.0.1:" + (3181 + i);
routingServiceBuilders[i] = RoutingUtils.buildRoutingService(finagleNameStr);
SocketAddress address = new InetSocketAddress("127.0.0.1", 3181 + i);
regionMap.put(address, "region-" + i);
}
RegionsRoutingService regionsRoutingService = RegionsRoutingService.newBuilder().resolver(new DefaultRegionResolver(regionMap)).routingServiceBuilders(routingServiceBuilders).build();
regionsRoutingService.startService();
RoutingService.RoutingContext routingContext = RoutingService.RoutingContext.of(new DefaultRegionResolver()).addTriedHost(new InetSocketAddress("127.0.0.1", 3183), StatusCode.WRITE_EXCEPTION);
assertEquals(new InetSocketAddress("127.0.0.1", 3181), regionsRoutingService.getHost("any", routingContext));
routingContext = RoutingService.RoutingContext.of(new DefaultRegionResolver()).addTriedHost(new InetSocketAddress("127.0.0.1", 3181), StatusCode.WRITE_EXCEPTION);
assertEquals(new InetSocketAddress("127.0.0.1", 3182), regionsRoutingService.getHost("any", routingContext));
// add 3182 to routing context as tried host
routingContext.addTriedHost(new InetSocketAddress("127.0.0.1", 3182), StatusCode.WRITE_EXCEPTION);
assertEquals(new InetSocketAddress("127.0.0.1", 3183), regionsRoutingService.getHost("any", routingContext));
// add 3183 to routing context as tried host
routingContext.addTriedHost(new InetSocketAddress("127.0.0.1", 3183), StatusCode.WRITE_EXCEPTION);
try {
regionsRoutingService.getHost("any", routingContext);
fail("Should fail to get host since all regions are tried.");
} catch (NoBrokersAvailableException nbae) {
// expected
}
}
Aggregations