Search in sources :

Example 51 with JetInstance

use of com.hazelcast.jet.JetInstance in project hazelcast-jet by hazelcast.

the class JetSplitBrainTestSupport method createHazelcastInstanceInBrain.

/**
 * Starts a new {@code JetInstance} which is only able to communicate
 * with members on one of the two brains.
 * @param firstSubCluster jet instances in the first sub cluster
 * @param secondSubCluster jet instances in the first sub cluster
 * @param createOnFirstSubCluster if true, new instance is created on the first sub cluster.
 * @return a HazelcastInstance whose {@code MockJoiner} has blacklisted the other brain's
 *         members and its connection manager blocks connections to other brain's members
 * @see TestHazelcastInstanceFactory#newHazelcastInstance(Address, com.hazelcast.config.Config, Address[])
 */
protected final JetInstance createHazelcastInstanceInBrain(JetInstance[] firstSubCluster, JetInstance[] secondSubCluster, boolean createOnFirstSubCluster) {
    Address newMemberAddress = nextAddress();
    JetInstance[] instancesToBlock = createOnFirstSubCluster ? secondSubCluster : firstSubCluster;
    List<Address> addressesToBlock = new ArrayList<>(instancesToBlock.length);
    for (JetInstance anInstancesToBlock : instancesToBlock) {
        if (isInstanceActive(anInstancesToBlock)) {
            addressesToBlock.add(getAddress(anInstancesToBlock.getHazelcastInstance()));
            // block communication from these instances to the new address
            FirewallingConnectionManager connectionManager = getFireWalledConnectionManager(anInstancesToBlock.getHazelcastInstance());
            connectionManager.blockNewConnection(newMemberAddress);
            connectionManager.closeActiveConnection(newMemberAddress);
        }
    }
    // indicate we need to unblacklist addresses from joiner when split-brain will be healed
    unblacklistHint = true;
    // create a new Hazelcast instance which has blocked addresses blacklisted in its joiner
    return createJetMember(createConfig(), addressesToBlock.toArray(new Address[addressesToBlock.size()]));
}
Also used : Address(com.hazelcast.nio.Address) FirewallingConnectionManager(com.hazelcast.nio.tcp.FirewallingConnectionManager) JetInstance(com.hazelcast.jet.JetInstance) ArrayList(java.util.ArrayList)

Example 52 with JetInstance

use of com.hazelcast.jet.JetInstance in project hazelcast-jet by hazelcast.

the class JetSplitBrainTestSupport method healSplitBrain.

private void healSplitBrain(JetInstance[] instances, int firstSubClusterSize) {
    applyOnBrains(instances, firstSubClusterSize, SplitBrainTestSupport::unblockCommunicationBetween);
    if (unblacklistHint) {
        applyOnBrains(instances, firstSubClusterSize, JetSplitBrainTestSupport::unblacklistJoinerBetween);
    }
    for (JetInstance instance : instances) {
        assertClusterSizeEventually(instances.length, instance.getHazelcastInstance());
    }
    waitAllForSafeState(Stream.of(instances).map(JetInstance::getHazelcastInstance).collect(toList()));
}
Also used : SplitBrainTestSupport(com.hazelcast.test.SplitBrainTestSupport) JetInstance(com.hazelcast.jet.JetInstance)

Example 53 with JetInstance

use of com.hazelcast.jet.JetInstance in project hazelcast-jet by hazelcast.

the class JetSplitBrainTestSupport method testSplitBrain.

final void testSplitBrain(int firstSubClusterSize, int secondSubClusterSize, Consumer<JetInstance[]> beforeSplit, BiConsumer<JetInstance[], JetInstance[]> onSplit, Consumer<JetInstance[]> afterMerge) {
    checkPositive(firstSubClusterSize, "invalid first sub cluster size: " + firstSubClusterSize);
    checkPositive(secondSubClusterSize, "invalid second sub cluster size: " + secondSubClusterSize);
    JetConfig config = createConfig();
    int clusterSize = firstSubClusterSize + secondSubClusterSize;
    JetInstance[] instances = startInitialCluster(config, clusterSize);
    if (beforeSplit != null) {
        beforeSplit.accept(instances);
    }
    createSplitBrain(instances, firstSubClusterSize, secondSubClusterSize);
    Brains brains = getBrains(instances, firstSubClusterSize, secondSubClusterSize);
    if (onSplit != null) {
        onSplit.accept(brains.firstSubCluster, brains.secondSubCluster);
    }
    healSplitBrain(instances, firstSubClusterSize);
    if (afterMerge != null) {
        afterMerge.accept(instances);
    }
}
Also used : JetInstance(com.hazelcast.jet.JetInstance) JetConfig(com.hazelcast.jet.config.JetConfig)

Example 54 with JetInstance

use of com.hazelcast.jet.JetInstance in project hazelcast-jet by hazelcast.

the class ManualRestartTest method when_jobIsCompleted_then_isCannotBeRestarted.

@Test(expected = IllegalStateException.class)
public void when_jobIsCompleted_then_isCannotBeRestarted() {
    // Given that the job is completed
    JetInstance client = createJetClient();
    Job job = client.newJob(dag);
    job.cancel();
    try {
        job.join();
        fail();
    } catch (CancellationException ignored) {
    }
    // Then, the job cannot restart
    job.restart();
}
Also used : CancellationException(java.util.concurrent.CancellationException) JetInstance(com.hazelcast.jet.JetInstance) Job(com.hazelcast.jet.Job) Test(org.junit.Test)

Example 55 with JetInstance

use of com.hazelcast.jet.JetInstance in project hazelcast-jet by hazelcast.

the class OperationTimeoutTest method when_slowRunningOperationOnMultipleNodes_doesNotTimeout.

@Test
public void when_slowRunningOperationOnMultipleNodes_doesNotTimeout() throws Throwable {
    // Given
    JetInstance instance = createJetMember(config);
    createJetMember(config);
    DAG dag = new DAG();
    dag.newVertex("slow", SlowProcessor::new);
    // When
    executeAndPeel(instance.newJob(dag));
}
Also used : JetInstance(com.hazelcast.jet.JetInstance) Test(org.junit.Test)

Aggregations

JetInstance (com.hazelcast.jet.JetInstance)84 Test (org.junit.Test)45 Job (com.hazelcast.jet.Job)32 JetConfig (com.hazelcast.jet.config.JetConfig)22 MockPS (com.hazelcast.jet.core.TestProcessors.MockPS)14 Pipeline (com.hazelcast.jet.pipeline.Pipeline)14 JobConfig (com.hazelcast.jet.config.JobConfig)13 StuckProcessor (com.hazelcast.jet.core.TestProcessors.StuckProcessor)12 DAG (com.hazelcast.jet.core.DAG)10 ExpectedException (org.junit.rules.ExpectedException)10 Jet (com.hazelcast.jet.Jet)9 Assert.assertEquals (org.junit.Assert.assertEquals)9 JetService (com.hazelcast.jet.impl.JetService)8 Map (java.util.Map)8 CountDownLatch (java.util.concurrent.CountDownLatch)8 JobRepository (com.hazelcast.jet.impl.JobRepository)7 Sources (com.hazelcast.jet.pipeline.Sources)7 CancellationException (java.util.concurrent.CancellationException)7 Assert.assertNotNull (org.junit.Assert.assertNotNull)7 Before (org.junit.Before)7