public void testRegisterHttpTransport() { Settings settings = Settings.builder().put(NetworkModule.HTTP_TYPE_SETTING.getKey(), "custom").build(); NetworkModule module = new NetworkModule( new NetworkService(settings), settings, false, new NamedWriteableRegistry()); module.registerHttpTransport("custom", FakeHttpTransport.class); assertBinding(module, HttpServerTransport.class, FakeHttpTransport.class); // check registration not allowed for transport only module = new NetworkModule( new NetworkService(settings), settings, true, new NamedWriteableRegistry()); try { module.registerHttpTransport("custom", FakeHttpTransport.class); fail(); } catch (IllegalArgumentException e) { assertTrue(e.getMessage().contains("Cannot register http transport")); assertTrue(e.getMessage().contains("for transport client")); } // not added if http is disabled settings = Settings.builder().put(NetworkModule.HTTP_ENABLED.getKey(), false).build(); module = new NetworkModule( new NetworkService(settings), settings, false, new NamedWriteableRegistry()); assertNotBound(module, HttpServerTransport.class); }
public void testSerializeRequest() throws IOException { ClusterRerouteRequest req = new ClusterRerouteRequest(); req.setRetryFailed(randomBoolean()); req.dryRun(randomBoolean()); req.explain(randomBoolean()); req.add(new AllocateEmptyPrimaryAllocationCommand("foo", 1, "bar", randomBoolean())); req.timeout(TimeValue.timeValueMillis(randomIntBetween(0, 100))); BytesStreamOutput out = new BytesStreamOutput(); req.writeTo(out); BytesReference bytes = out.bytes(); NetworkModule networkModule = new NetworkModule(null, Settings.EMPTY, true); NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(networkModule.getNamedWriteables()); StreamInput wrap = new NamedWriteableAwareStreamInput(bytes.streamInput(), namedWriteableRegistry); ClusterRerouteRequest deserializedReq = new ClusterRerouteRequest(); deserializedReq.readFrom(wrap); assertEquals(req.isRetryFailed(), deserializedReq.isRetryFailed()); assertEquals(req.dryRun(), deserializedReq.dryRun()); assertEquals(req.explain(), deserializedReq.explain()); assertEquals(req.timeout(), deserializedReq.timeout()); assertEquals( 1, deserializedReq .getCommands() .commands() .size()); // allocation commands have their own tests assertEquals( req.getCommands().commands().size(), deserializedReq.getCommands().commands().size()); }
public void testRegisterCatRestHandler() { Settings settings = Settings.EMPTY; NetworkModule module = new NetworkModule(new NetworkService(settings), settings, false, null); module.registerRestHandler(FakeCatRestHandler.class); // also check a builtin is bound assertSetMultiBinding( module, AbstractCatAction.class, FakeCatRestHandler.class, RestNodesAction.class); }
public void testRegisterTransport() { Settings settings = Settings.builder().put(NetworkModule.TRANSPORT_TYPE_KEY, "custom").build(); NetworkModule module = new NetworkModule(new NetworkService(settings), settings, false, null); module.registerTransport("custom", FakeTransport.class); assertBinding(module, Transport.class, FakeTransport.class); // check it works with transport only as well module = new NetworkModule(new NetworkService(settings), settings, true, null); module.registerTransport("custom", FakeTransport.class); assertBinding(module, Transport.class, FakeTransport.class); }
public void testRegisterTaskStatus() { NamedWriteableRegistry registry = new NamedWriteableRegistry(); Settings settings = Settings.EMPTY; NetworkModule module = new NetworkModule(new NetworkService(settings), settings, false, registry); // Builtin reader comes back assertNotNull(registry.getReader(Task.Status.class, ReplicationTask.Status.NAME)); module.registerTaskStatus(DummyTaskStatus.NAME, DummyTaskStatus::new); assertEquals( "test", expectThrows( UnsupportedOperationException.class, () -> registry.getReader(Task.Status.class, DummyTaskStatus.NAME).read(null)) .getMessage()); }
public void testRegisterRestHandler() { Settings settings = Settings.EMPTY; NetworkModule module = new NetworkModule(new NetworkService(settings), settings, false, null); module.registerRestHandler(FakeRestHandler.class); // also check a builtin is bound assertSetMultiBinding(module, RestHandler.class, FakeRestHandler.class, RestMainAction.class); // check registration not allowed for transport only module = new NetworkModule(new NetworkService(settings), settings, true, null); try { module.registerRestHandler(FakeRestHandler.class); fail(); } catch (IllegalArgumentException e) { assertTrue(e.getMessage().contains("Cannot register rest handler")); assertTrue(e.getMessage().contains("for transport client")); } }
public void onModule(NetworkModule transportModule) { transportModule.registerTransportService("internal", InternalTransportService.class); }
public void onModule(NetworkModule module) { module.registerTransportService("intercepting", InterceptingTransportService.class); }