Search in sources :

Example 1 with TextProtocolClient

use of com.hazelcast.internal.nio.ascii.TextProtocolClient in project hazelcast by hazelcast.

the class SingleProtocolHandlerRegressionTest method testWrongProtocolRegressionTest.

/**
 * Regression test for #19756
 */
@Test
@Repeat(50)
public void testWrongProtocolRegressionTest() {
    HazelcastInstance instance = Hazelcast.newHazelcastInstance(createMemberEndpointConfig());
    ServerConnectionManager connectionManager = ((HazelcastInstanceProxy) instance).getOriginal().node.getServer().getConnectionManager(CLIENT);
    // Get address of the client endpoint
    InetAddress address = instance.getCluster().getLocalMember().getSocketAddress(CLIENT).getAddress();
    int port = instance.getCluster().getLocalMember().getSocketAddress(CLIENT).getPort();
    textProtocolClient = new TextProtocolClient(address, port);
    textProtocolClient.connect();
    assertTrueEventually(() -> assertTrue(textProtocolClient.isConnected()), ASSERT_TRUE_TIMEOUT_SECS);
    assertTrueEventually(() -> assertEquals(connectionManager.getConnections().size(), 1), ASSERT_TRUE_TIMEOUT_SECS);
    // Send wrong protocol data to client endpoint
    textProtocolClient.sendData("AAACP2CP2");
    // Assert that connection must be closed on the member side
    assertTrueEventually(() -> assertTrue("Connection must be closed on the member side", connectionManager.getConnections().isEmpty()), ASSERT_TRUE_TIMEOUT_SECS);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ServerConnectionManager(com.hazelcast.internal.server.ServerConnectionManager) TextProtocolClient(com.hazelcast.internal.nio.ascii.TextProtocolClient) InetAddress(java.net.InetAddress) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test) Repeat(com.hazelcast.test.annotation.Repeat)

Aggregations

HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 TextProtocolClient (com.hazelcast.internal.nio.ascii.TextProtocolClient)1 ServerConnectionManager (com.hazelcast.internal.server.ServerConnectionManager)1 NightlyTest (com.hazelcast.test.annotation.NightlyTest)1 Repeat (com.hazelcast.test.annotation.Repeat)1 InetAddress (java.net.InetAddress)1 Test (org.junit.Test)1