use of org.jboss.remoting3.remote.RemoteConnection.RemoteWriteListener in project jboss-remoting by jboss-remoting.
the class HeartbeatTestCase method testDefaultHeartbeat.
/**
* Test that heartbeat can be set and can be disabled by setting it to 0
*
* @throws Exception
*/
@Test
public void testDefaultHeartbeat() throws Exception {
Channel clientChannel = null;
Channel serverChannel = null;
Closeable streamServer = null;
Connection connection = null;
Registration serviceRegistration = null;
final Endpoint endpoint = Endpoint.builder().setEndpointName("test").build();
NetworkServerProvider networkServerProvider = endpoint.getConnectionProviderInterface("remote", NetworkServerProvider.class);
final SecurityDomain.Builder domainBuilder = SecurityDomain.builder();
final SimpleMapBackedSecurityRealm mainRealm = new SimpleMapBackedSecurityRealm();
domainBuilder.addRealm("mainRealm", mainRealm).build();
domainBuilder.setDefaultRealmName("mainRealm");
domainBuilder.setPermissionMapper((permissionMappable, roles) -> PermissionVerifier.ALL);
final PasswordFactory passwordFactory = PasswordFactory.getInstance("clear");
mainRealm.setPasswordMap("bob", passwordFactory.generatePassword(new ClearPasswordSpec("pass".toCharArray())));
final SaslServerFactory saslServerFactory = new ServiceLoaderSaslServerFactory(HeartbeatTestCase.class.getClassLoader());
final SaslAuthenticationFactory.Builder builder = SaslAuthenticationFactory.builder();
builder.setSecurityDomain(domainBuilder.build());
builder.setFactory(saslServerFactory);
builder.setMechanismConfigurationSelector(mechanismInformation -> SaslMechanismInformation.Names.SCRAM_SHA_256.equals(mechanismInformation.getMechanismName()) ? MechanismConfiguration.EMPTY : null);
final SaslAuthenticationFactory saslAuthenticationFactory = builder.build();
streamServer = networkServerProvider.createServer(new InetSocketAddress("localhost", 30123), OptionMap.create(Options.SSL_ENABLED, Boolean.FALSE), saslAuthenticationFactory, SSLContext.getDefault());
final FutureResult<Channel> passer = new FutureResult<Channel>();
serviceRegistration = endpoint.registerService("org.jboss.test", new OpenListener() {
public void channelOpened(final Channel channel) {
passer.setResult(channel);
}
public void registrationTerminated() {
}
}, OptionMap.EMPTY);
IoFuture<Connection> futureConnection = AuthenticationContext.empty().with(MatchRule.ALL, AuthenticationConfiguration.empty().useName("bob").usePassword("pass").setSaslMechanismSelector(SaslMechanismSelector.NONE.addMechanism("SCRAM-SHA-256"))).run(new PrivilegedAction<IoFuture<Connection>>() {
public IoFuture<Connection> run() {
try {
return endpoint.connect(new URI("remote://localhost:30123"), OptionMap.EMPTY);
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
}
});
connection = futureConnection.get();
IoFuture<Channel> futureChannel = connection.openChannel("org.jboss.test", OptionMap.EMPTY);
clientChannel = futureChannel.get();
serverChannel = passer.getIoFuture().get();
assertNotNull(serverChannel);
RemoteConnectionChannel remoteClientChannel = (RemoteConnectionChannel) clientChannel;
assertEquals(RemotingOptions.DEFAULT_HEARTBEAT_INTERVAL, Utils.getInstanceValue(remoteClientChannel.getRemoteConnection(), "heartbeatInterval"));
RemoteWriteListener clientWriteListener = (RemoteWriteListener) Utils.getInstanceValue(remoteClientChannel.getRemoteConnection(), "writeListener");
assertNotNull(Utils.getInstanceValue(clientWriteListener, "heartKey"));
afterTest(clientChannel, serverChannel, connection, serviceRegistration);
destroy(endpoint, streamServer);
}
use of org.jboss.remoting3.remote.RemoteConnection.RemoteWriteListener in project jboss-remoting by jboss-remoting.
the class HeartbeatTestCase method testDisableHeartbeat.
/**
* Test that heartbeat can be set and can be disabled by setting it to 0
*
* @throws Exception
*/
@Test
public void testDisableHeartbeat() throws Exception {
Channel clientChannel = null;
Channel serverChannel = null;
Closeable streamServer = null;
Connection connection = null;
Registration serviceRegistration = null;
final Endpoint endpoint = Endpoint.builder().setEndpointName("test").build();
NetworkServerProvider networkServerProvider = endpoint.getConnectionProviderInterface("remote", NetworkServerProvider.class);
final SecurityDomain.Builder domainBuilder = SecurityDomain.builder();
final SimpleMapBackedSecurityRealm mainRealm = new SimpleMapBackedSecurityRealm();
domainBuilder.addRealm("mainRealm", mainRealm).build();
domainBuilder.setDefaultRealmName("mainRealm");
domainBuilder.setPermissionMapper((permissionMappable, roles) -> PermissionVerifier.ALL);
final PasswordFactory passwordFactory = PasswordFactory.getInstance("clear");
mainRealm.setPasswordMap("bob", passwordFactory.generatePassword(new ClearPasswordSpec("pass".toCharArray())));
final SaslServerFactory saslServerFactory = new ServiceLoaderSaslServerFactory(HeartbeatTestCase.class.getClassLoader());
final SaslAuthenticationFactory.Builder builder = SaslAuthenticationFactory.builder();
builder.setSecurityDomain(domainBuilder.build());
builder.setFactory(saslServerFactory);
builder.setMechanismConfigurationSelector(mechanismInformation -> SaslMechanismInformation.Names.SCRAM_SHA_256.equals(mechanismInformation.getMechanismName()) ? MechanismConfiguration.EMPTY : null);
final SaslAuthenticationFactory saslAuthenticationFactory = builder.build();
streamServer = networkServerProvider.createServer(new InetSocketAddress("localhost", 30123), OptionMap.create(Options.SSL_ENABLED, Boolean.FALSE), saslAuthenticationFactory, SSLContext.getDefault());
final FutureResult<Channel> passer = new FutureResult<Channel>();
serviceRegistration = endpoint.registerService("org.jboss.test", new OpenListener() {
public void channelOpened(final Channel channel) {
passer.setResult(channel);
}
public void registrationTerminated() {
}
}, OptionMap.EMPTY);
IoFuture<Connection> futureConnection = AuthenticationContext.empty().with(MatchRule.ALL, AuthenticationConfiguration.empty().useName("bob").usePassword("pass").setSaslMechanismSelector(SaslMechanismSelector.NONE.addMechanism("SCRAM-SHA-256"))).run(new PrivilegedAction<IoFuture<Connection>>() {
public IoFuture<Connection> run() {
try {
return endpoint.connect(new URI("remote://localhost:30123"), OptionMap.create(RemotingOptions.HEARTBEAT_INTERVAL, 0));
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
}
});
connection = futureConnection.get();
IoFuture<Channel> futureChannel = connection.openChannel("org.jboss.test", OptionMap.EMPTY);
clientChannel = futureChannel.get();
serverChannel = passer.getIoFuture().get();
assertNotNull(serverChannel);
RemoteConnectionChannel remoteClientChannel = (RemoteConnectionChannel) clientChannel;
assertEquals(0, Utils.getInstanceValue(remoteClientChannel.getRemoteConnection(), "heartbeatInterval"));
RemoteWriteListener clientWriteListener = (RemoteWriteListener) Utils.getInstanceValue(remoteClientChannel.getRemoteConnection(), "writeListener");
assertNull(Utils.getInstanceValue(clientWriteListener, "heartKey"));
afterTest(clientChannel, serverChannel, connection, serviceRegistration);
destroy(endpoint, streamServer);
}
Aggregations