@Override Set<IClient> getClientsForTest() { BaseHandler baseHandler = new BaseHandler(); client = new BaseClient(router, 0L); return new ImmutableSet.Builder<IClient>() .add(baseHandler) .build(); }
@Override Set<IClient> getClientsForTest() { ManagementHandler managementHandler = new ManagementHandler(); client = new ManagementClient(router, 0L); return new ImmutableSet.Builder<IClient>() .add(new BaseHandler()) .add(managementHandler) .build(); }
@Override Set<IClient> getClientsForTest() { LogUnitHandler logUnitHandler = new LogUnitHandler(); client = new LogUnitClient(router, 0L); return new ImmutableSet.Builder<IClient>() .add(new BaseHandler()) .add(logUnitHandler) .build(); }
@Override Set<IClient> getClientsForTest() { LayoutHandler layoutHandler = new LayoutHandler(); client = new LayoutClient(router, 0L); return new ImmutableSet.Builder<IClient>() .add(new BaseHandler()) .add(layoutHandler) .build(); }
router.addClient(new LayoutHandler()) .addClient(new ManagementHandler()) .addClient(new BaseHandler());
addClient(new BaseHandler());
/** * Function for obtaining a router, given a runtime and an endpoint. * * @param runtime The CorfuRuntime to obtain a router for. * @param endpoint An endpoint string for the router. * @return */ protected IClientRouter getRouterFunction(CorfuRuntime runtime, String endpoint) { runtimeRouterMap.putIfAbsent(runtime, new ConcurrentHashMap<>()); if (!endpoint.startsWith("test:") && !endpoint.startsWith(testHostname)) { throw new RuntimeException("Unsupported endpoint in test: " + endpoint); } return runtimeRouterMap.get(runtime).computeIfAbsent(endpoint, x -> { String serverName = endpoint.startsWith(testHostname) ? endpoint.substring(endpoint.indexOf("test"), endpoint.length() - 1) : endpoint; TestClientRouter tcn = new TestClientRouter(testServerMap.get(serverName).getServerRouter()); tcn.addClient(new BaseHandler()) .addClient(new SequencerHandler()) .addClient(new LayoutHandler()) .addClient(new LogUnitHandler()) .addClient(new ManagementHandler()); return tcn; } ); }
/** * Function for obtaining a router, given a runtime and an endpoint. * * @param runtime The CorfuRuntime to obtain a router for. * @param endpoint An endpoint string for the router. * @return */ private IClientRouter getRouterFunction(CorfuRuntime runtime, String endpoint) { runtimeRouterMap.putIfAbsent(runtime, new ConcurrentHashMap<>()); if (!endpoint.startsWith("test:")) { throw new RuntimeException("Unsupported endpoint in test: " + endpoint); } return runtimeRouterMap.get(runtime).computeIfAbsent(endpoint, x -> { TestClientRouter tcn = new TestClientRouter(serverRouter); tcn.addClient(new BaseHandler()) .addClient(new SequencerHandler()) .addClient(new LayoutHandler()) .addClient(new LogUnitHandler()) .addClient(new ManagementHandler()); return tcn; } ); }
/** * Function for obtaining a router, given a runtime and an endpoint. * * @param runtime The CorfuRuntime to obtain a router for. * @param endpoint An endpoint string for the router. * @return */ private IClientRouter getRouterFunction(CorfuRuntime runtime, String endpoint) { runtimeRouterMap.putIfAbsent(runtime, new ConcurrentHashMap<>()); if (!endpoint.startsWith("test:")) { throw new RuntimeException("Unsupported endpoint in test: " + endpoint); } return runtimeRouterMap.get(runtime).computeIfAbsent(endpoint, x -> { TestClientRouter tcn = new TestClientRouter(router); tcn.addClient(new BaseHandler()) .addClient(new SequencerHandler()) .addClient(new LayoutHandler()) .addClient(new LogUnitHandler()) .addClient(new ManagementHandler()); return tcn; } ); } }
void runWithBaseServer(NettyServerDataConstructor nsdc, NettyClientRouterConstructor ncrc, NettyCommFunction actionFn) throws Exception { int port = findRandomOpenPort(); NettyServerData d = nsdc.createNettyServerData(port); NettyClientRouter ncr = null; try { d.bootstrapServer(); ncr = ncrc.createNettyClientRouter(port); ncr.addClient(new BaseHandler()); ncr.start(); actionFn.runTest(ncr, d); } catch (Exception ex) { log.error("Exception ", ex); throw ex; } finally { try { if (ncr != null) {ncr.stop(true);} } catch (Exception ex) { log.warn("Error shutting down client...", ex); } d.shutdownServer(); } }
@Before public void setupRouter() { TestServerRouter tsr = new TestServerRouter(); BaseServer bs = new BaseServer(ServerContextBuilder.defaultTestContext(0)); tsr.addServer(bs); tcr = new TestClientRouter(tsr); BaseHandler baseHandler = new BaseHandler(); tcr.addClient(baseHandler); bc = new BaseClient(tcr, 0L); }
/** * Setup a cluster of 1 node. Bootstrap the node with a wrong layout. * Bootstrap the cluster using the BootstrapUtil. It should assert that the node already * bootstrapped is with the wrong layout and then fail with the AlreadyBootstrappedException. */ @Test public void test1NodeBootstrapWithWrongBootstrappedLayoutServer() throws Exception { // Set up cluster of 1 node. final int PORT_0 = 9000; Process corfuServer_1 = runPersistentServer(corfuSingleNodeHost, PORT_0, false); final Layout layout = getLayout(1); final int retries = 3; IClientRouter router = new NettyClientRouter(NodeLocator .parseString(corfuSingleNodeHost + ":" + PORT_0), CorfuRuntime.CorfuRuntimeParameters.builder().build()); router.addClient(new LayoutHandler()).addClient(new BaseHandler()); Layout wrongLayout = new Layout(layout); wrongLayout.getLayoutServers().add("localhost:9005"); retryBootstrapOperation(() -> CFUtils.getUninterruptibly( new LayoutClient(router, layout.getEpoch()).bootstrapLayout(wrongLayout))); assertThatThrownBy(() -> BootstrapUtil.bootstrap(layout, retries, PARAMETERS.TIMEOUT_SHORT)) .hasCauseInstanceOf(AlreadyBootstrappedException.class); shutdownCorfuServer(corfuServer_1); }
/** * Setup a cluster of 1 node. Bootstrap the node with a wrong layout. * Bootstrap the cluster using the BootstrapUtil. It should assert that the node already * bootstrapped is with the wrong layout and then fail with the AlreadyBootstrappedException. */ @Test public void test1NodeBootstrapWithWrongBootstrappedManagementServer() throws Exception { // Set up cluster of 1 node. final int PORT_0 = 9000; Process corfuServer_1 = runPersistentServer(corfuSingleNodeHost, PORT_0, false); final Layout layout = getLayout(1); final int retries = 3; IClientRouter router = new NettyClientRouter(NodeLocator .parseString(corfuSingleNodeHost + ":" + PORT_0), CorfuRuntime.CorfuRuntimeParameters.builder().build()); router.addClient(new LayoutHandler()) .addClient(new ManagementHandler()) .addClient(new BaseHandler()); Layout wrongLayout = new Layout(layout); final ManagementClient managementClient = new ManagementClient(router, layout.getEpoch()); wrongLayout.getLayoutServers().add("localhost:9005"); retryBootstrapOperation(() -> CFUtils.getUninterruptibly( managementClient.bootstrapManagement(wrongLayout))); assertThatThrownBy(() -> BootstrapUtil.bootstrap(layout, retries, PARAMETERS.TIMEOUT_SHORT)) .hasCauseInstanceOf(AlreadyBootstrappedException.class); shutdownCorfuServer(corfuServer_1); }
/** * Setup a cluster of 1 node. Bootstrap the nodes. * Bootstrap the cluster using the BootstrapUtil. It should assert that the node already * bootstrapped is with the same layout and then bootstrap the cluster. */ @Test public void test1NodeBootstrapWithBootstrappedNode() throws Exception { // Set up cluster of 1 nodes. final int PORT_0 = 9000; Process corfuServer_1 = runPersistentServer(corfuSingleNodeHost, PORT_0, false); final Layout layout = getLayout(1); final int retries = 5; IClientRouter router = new NettyClientRouter(NodeLocator .parseString(corfuSingleNodeHost + ":" + PORT_0), CorfuRuntime.CorfuRuntimeParameters.builder().build()); router.addClient(new LayoutHandler()).addClient(new BaseHandler()); retryBootstrapOperation(() -> CFUtils.getUninterruptibly( new LayoutClient(router, layout.getEpoch()).bootstrapLayout(layout))); retryBootstrapOperation(() -> CFUtils.getUninterruptibly( new ManagementClient(router, layout.getEpoch()).bootstrapManagement(layout))); BootstrapUtil.bootstrap(layout, retries, PARAMETERS.TIMEOUT_SHORT); CorfuRuntime corfuRuntime = createDefaultRuntime(); assertThat(corfuRuntime.getLayoutView().getLayout().equals(layout)).isTrue(); shutdownCorfuServer(corfuServer_1); }