TmRpcClient extends AbstractRpcRemotingClient { @Override public void init() { if (initialized.compareAndSet(false, true)) { enableDegrade = CONFIG.getBoolean(ConfigurationKeys.SERVICE_PREFIX + ConfigurationKeys.ENABLE_DEGRADE_POSTFIX); super.init(); } } private  TmRpcClient(NettyClientConfig nettyClientConfig,
                        EventExecutorGroup eventExecutorGroup,
                        ThreadPoolExecutor messageExecutor); static TmRpcClient getInstance(String applicationId, String transactionServiceGroup); static TmRpcClient getInstance(); void setApplicationId(String applicationId); void setTransactionServiceGroup(String transactionServiceGroup); @Override void init(); @Override void destroy(); @Override String getTransactionServiceGroup(); @Override void onRegisterMsgSuccess(String serverAddress, Channel channel, Object response,
                                     AbstractMessage requestMessage); @Override void onRegisterMsgFail(String serverAddress, Channel channel, Object response,
                                  AbstractMessage requestMessage); static boolean enableDegrade; }
@Test public void testInit() throws Exception { String applicationId = "app 1"; String transactionServiceGroup = "group A"; TmRpcClient tmRpcClient = TmRpcClient.getInstance(applicationId, transactionServiceGroup); tmRpcClient.init(); Field clientBootstrapField = getDeclaredField(tmRpcClient, "clientBootstrap"); clientBootstrapField.setAccessible(true); RpcClientBootstrap clientBootstrap = (RpcClientBootstrap)clientBootstrapField.get(tmRpcClient); Field bootstrapField = getDeclaredField(clientBootstrap, "bootstrap"); bootstrapField.setAccessible(true); Bootstrap bootstrap = (Bootstrap) bootstrapField.get(clientBootstrap); Assertions.assertNotNull(bootstrap); Field optionsField = getDeclaredField(bootstrap, "options"); optionsField.setAccessible(true); Map<ChannelOption<?>, Object> options = (Map<ChannelOption<?>, Object>)optionsField.get(bootstrap); Assertions.assertTrue(Boolean.TRUE.equals(options.get(ChannelOption.TCP_NODELAY))); Assertions.assertTrue(Boolean.TRUE.equals(options.get(ChannelOption.SO_KEEPALIVE))); Assertions.assertEquals(10000, options.get(ChannelOption.CONNECT_TIMEOUT_MILLIS)); Assertions.assertTrue(Boolean.TRUE.equals(options.get(ChannelOption.SO_KEEPALIVE))); Assertions.assertEquals(153600, options.get(ChannelOption.SO_RCVBUF)); Field channelFactoryField = getDeclaredField(bootstrap, "channelFactory"); channelFactoryField.setAccessible(true); ChannelFactory<? extends Channel> channelFactory = (ChannelFactory<? extends Channel>)channelFactoryField.get(bootstrap); Assertions.assertNotNull(channelFactory); Assertions.assertTrue(channelFactory.newChannel() instanceof NioSocketChannel); }