@Test public void messageHandlerProcessTest() { BootstrapTransportService bService = new BootstrapTransportService(); KeyStoreService keyStoreService = mock(KeyStoreService.class); KeyPair keyPair = keyPairGenerator.generateKeyPair(); PublicKey publicKey = keyPair.getPublic(); PrivateKey privateKey = keyPair.getPrivate(); when(keyStoreService.getPublicKey()).thenReturn(publicKey); when(keyStoreService.getPrivateKey()).thenReturn(privateKey); ReflectionTestUtils.setField(bService, "supportUnencryptedConnection", true); ReflectionTestUtils.setField(bService, "keyStoreService", keyStoreService); ReflectionTestUtils.setField(bService, "properties", new Properties()); bService.lookupAndInit(); MessageHandler handler = (BootstrapTransportService.BootstrapMessageHandler) ReflectionTestUtils.getField(bService, "handler"); SessionInitMessage encryptedSessionInitMessage = mockForSessionInitMessage(true); SessionInitMessage nonEncryptedSessionInitMessage = mockForSessionInitMessage(false); handler.process(encryptedSessionInitMessage); handler.process(nonEncryptedSessionInitMessage); verify(encryptedSessionInitMessage, timeout(1000)).getEncodedMessageData(); verify(nonEncryptedSessionInitMessage, timeout(1000)).getEncodedMessageData(); }
/** * Start zk. * * @throws Exception in case of error */ private void startZk() throws Exception { // NOSONAR if (getNodeConfig().isZkEnabled()) { LOG.info( "Bootstrap service starting ZooKepper connection to {}", getNodeConfig().getZkHostPortList()); BootstrapNodeInfo nodeInfo = new BootstrapNodeInfo(); ByteBuffer keyData = ByteBuffer.wrap(bootstrapKeyStoreService.getPublicKey().getEncoded()); LOG.trace( "Bootstrap service: registering in ZK: thriftHost {}; " + "thriftPort {}; nettyHost {}; nettyPort {}", getNodeConfig().getThriftHost(), getNodeConfig().getThriftPort()); nodeInfo.setConnectionInfo( new ConnectionInfo( getNodeConfig().getThriftHost(), getNodeConfig().getThriftPort(), keyData)); nodeInfo.setTransports(new ArrayList<>()); nodeInfo.setTimeStarted(System.currentTimeMillis()); bootstrapNode = new BootstrapNode(nodeInfo, zkClient); if (bootstrapNode != null) { bootstrapNode.start(); } } }