@Override Set<IClient> getClientsForTest() { LayoutHandler layoutHandler = new LayoutHandler(); client = new LayoutClient(router, 0L); return new ImmutableSet.Builder<IClient>() .add(new BaseHandler()) .add(layoutHandler) .build(); }
IClientRouter router = new NettyClientRouter(NodeLocator.parseString(server), corfuRuntimeParameters); router.addClient(new LayoutHandler()) .addClient(new ManagementHandler()) .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; } ); } }
/** * 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); }