Search in sources :

Example 36 with Connection

use of com.hazelcast.internal.nio.Connection in project hazelcast by hazelcast.

the class ClusterMismatchOp method run.

@Override
public void run() {
    NodeEngineImpl nodeEngine = (NodeEngineImpl) getNodeEngine();
    Connection connection = getConnection();
    String message = "Node could not join cluster at node: " + connection.getRemoteAddress() + " Cause: the target cluster has a different cluster-name";
    Node node = nodeEngine.getNode();
    LinkedAddresses linkedAddresses = node.getLocalAddressRegistry().linkedAddressesOf(getCallerUuid());
    connection.close(message, null);
    ILogger logger = nodeEngine.getLogger("com.hazelcast.cluster");
    logger.warning(message);
    if (linkedAddresses != null) {
        for (Address address : linkedAddresses.getAllAddresses()) {
            node.getJoiner().blacklist(address, true);
        }
    } else {
        node.getJoiner().blacklist(getCallerAddress(), true);
    }
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Address(com.hazelcast.cluster.Address) Node(com.hazelcast.instance.impl.Node) Connection(com.hazelcast.internal.nio.Connection) ILogger(com.hazelcast.logging.ILogger) LinkedAddresses(com.hazelcast.internal.server.tcp.LinkedAddresses)

Example 37 with Connection

use of com.hazelcast.internal.nio.Connection in project hazelcast by hazelcast.

the class SystemLogPlugin method render.

@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
private void render(DiagnosticsLogWriter writer, ConnectionEvent event) {
    if (event.added) {
        writer.startSection("ConnectionAdded");
    } else {
        writer.startSection("ConnectionRemoved");
    }
    Connection connection = event.connection;
    writer.writeEntry(connection.toString());
    if (connection instanceof ServerConnection) {
        writer.writeKeyValueEntry("type", ((ServerConnection) connection).getConnectionType());
    }
    writer.writeKeyValueEntry("isAlive", connection.isAlive());
    if (!event.added) {
        String closeReason = connection.getCloseReason();
        Throwable closeCause = connection.getCloseCause();
        if (closeReason == null && closeCause != null) {
            closeReason = closeCause.getMessage();
        }
        writer.writeKeyValueEntry("closeReason", closeReason == null ? "Unknown" : closeReason);
        if (closeCause != null) {
            writer.startSection("CloseCause");
            String s = closeCause.getClass().getName();
            String message = closeCause.getMessage();
            writer.writeEntry((message != null) ? (s + ": " + message) : s);
            for (StackTraceElement element : closeCause.getStackTrace()) {
                writer.writeEntry(element.toString());
            }
            writer.endSection();
        }
    }
    writer.endSection();
}
Also used : ServerConnection(com.hazelcast.internal.server.ServerConnection) Connection(com.hazelcast.internal.nio.Connection) ServerConnection(com.hazelcast.internal.server.ServerConnection)

Example 38 with Connection

use of com.hazelcast.internal.nio.Connection in project hazelcast by hazelcast.

the class TcpServerConnectionManager_AbstractConnectMemberTest method getOrConnect_whenNotConnected_thenEventuallyConnectionAvailable.

// ================== getOrConnect ======================================================
@Test
public void getOrConnect_whenNotConnected_thenEventuallyConnectionAvailable() {
    startAllTcpServers();
    Connection c = tcpServerA.getConnectionManager(MEMBER).getOrConnect(addressB);
    assertNull(c);
    connect(tcpServerA, addressB);
    assertEquals(1, tcpServerA.getConnectionManager(MEMBER).getConnections().size());
    assertEquals(1, tcpServerB.getConnectionManager(MEMBER).getConnections().size());
}
Also used : Connection(com.hazelcast.internal.nio.Connection) Test(org.junit.Test)

Example 39 with Connection

use of com.hazelcast.internal.nio.Connection in project hazelcast by hazelcast.

the class TcpServerConnection_AbstractTest method connect.

protected TcpServerConnection connect(final TcpServer service, final Address address) {
    service.getConnectionManager(MEMBER).getOrConnect(address);
    final AtomicReference<TcpServerConnection> ref = new AtomicReference<>();
    assertTrueEventually(() -> {
        Connection c = service.getConnectionManager(MEMBER).get(address);
        assertNotNull(c);
        ref.set((TcpServerConnection) c);
    });
    return ref.get();
}
Also used : ServerConnection(com.hazelcast.internal.server.ServerConnection) Connection(com.hazelcast.internal.nio.Connection) AtomicReference(java.util.concurrent.atomic.AtomicReference)

Example 40 with Connection

use of com.hazelcast.internal.nio.Connection in project hazelcast by hazelcast.

the class MemberReconnectionStressTest method test.

@Test
public void test() {
    /*
        The test will start 2 thread:
        - one will submit short batch jobs, serially, after joining the previous job
        - the other will keep dropping the member-to-member connection.

        The small jobs will often fail due to the reconnection, we check
        that the job completes in a limited time. We drop the connection
        at a rate lower than the normal job duration so there's
        typically at most 1 restart per job. We assert that the jobs
        eventually successfully complete.
         */
    Config config = defaultInstanceConfigWithJetEnabled();
    // The connection drop often causes regular IMap operations to fail - shorten the timeout so that
    // it recovers more quickly
    config.setProperty(ClusterProperty.OPERATION_CALL_TIMEOUT_MILLIS.getName(), "2000");
    config.setClusterName(randomName());
    HazelcastInstance inst1 = createHazelcastInstance(config);
    HazelcastInstance inst2 = createHazelcastInstance(config);
    logger.info("Instances started");
    new Thread(() -> {
        while (!terminated.get()) {
            Connection connection = null;
            while (connection == null) {
                connection = ImdgUtil.getMemberConnection(getNodeEngineImpl(inst1), getNodeEngineImpl(inst2).getThisAddress());
            }
            connection.close("test", new Exception("test failure"));
            logger.info("connection closed");
            sleepMillis(300);
        }
    }).start();
    DAG dag = new DAG();
    Vertex v1 = dag.newVertex("v1", () -> new MockP()).localParallelism(2);
    Vertex v2 = dag.newVertex("v2", () -> new MockP()).localParallelism(2);
    dag.edge(between(v1, v2).distributed());
    AtomicInteger jobCount = new AtomicInteger();
    new Thread(() -> {
        while (!terminated.get()) {
            try {
                inst1.getJet().newJob(dag).getFuture().join();
                logger.info("job completed");
                jobCount.incrementAndGet();
            } catch (Exception e) {
                logger.info("Job failed, ignoring it", e);
            }
        }
    }).start();
    // in a loop check that the `jobCount` is incremented at least every N seconds
    long lastIncrement = System.nanoTime();
    long lastJobCount = 0;
    long testEndTime = System.nanoTime() + MINUTES.toNanos(3);
    for (long now; (now = System.nanoTime()) < testEndTime; ) {
        if (jobCount.get() > lastJobCount) {
            lastIncrement = now;
            lastJobCount++;
        }
        if (NANOSECONDS.toSeconds(now - lastIncrement) > 30) {
            fail("jobCount didn't increment for 30 seconds");
        }
        sleepMillis(100);
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Config(com.hazelcast.config.Config) MockP(com.hazelcast.jet.core.TestProcessors.MockP) Connection(com.hazelcast.internal.nio.Connection) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Aggregations

Connection (com.hazelcast.internal.nio.Connection)41 Test (org.junit.Test)14 QuickTest (com.hazelcast.test.annotation.QuickTest)11 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)8 ServerConnection (com.hazelcast.internal.server.ServerConnection)7 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)7 ClientConnection (com.hazelcast.client.impl.connection.ClientConnection)6 Address (com.hazelcast.cluster.Address)6 HazelcastClientInstanceImpl (com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl)5 Member (com.hazelcast.cluster.Member)5 HazelcastInstance (com.hazelcast.core.HazelcastInstance)5 ConnectionListener (com.hazelcast.internal.nio.ConnectionListener)5 ClientConnectionManager (com.hazelcast.client.impl.connection.ClientConnectionManager)4 ILogger (com.hazelcast.logging.ILogger)4 QueryId (com.hazelcast.sql.impl.QueryId)4 Map (java.util.Map)4 UUID (java.util.UUID)4 ClientInvocation (com.hazelcast.client.impl.spi.impl.ClientInvocation)3 TargetDisconnectedException (com.hazelcast.spi.exception.TargetDisconnectedException)3 IOException (java.io.IOException)3