Search in sources :

Example 41 with HazelcastInstance

use of com.hazelcast.core.HazelcastInstance in project hazelcast by hazelcast.

the class InternalPartitionServiceLiteMemberTest method test_liteMemberCanTerminate_withClusterSize2.

@Test(timeout = 120000)
public void test_liteMemberCanTerminate_withClusterSize2() {
    final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    final HazelcastInstance lite1 = factory.newHazelcastInstance(liteMemberConfig);
    final HazelcastInstance lite2 = factory.newHazelcastInstance(liteMemberConfig);
    assertClusterSizeEventually(2, lite1);
    assertClusterSizeEventually(2, lite2);
    lite1.getLifecycleService().terminate();
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 42 with HazelcastInstance

use of com.hazelcast.core.HazelcastInstance in project hazelcast by hazelcast.

the class MigrationCommitServiceTest method migrateWithSuccess.

private void migrateWithSuccess(final MigrationInfo migration) {
    InternalPartitionServiceImpl partitionService = (InternalPartitionServiceImpl) getPartitionService(instances[0]);
    partitionService.getMigrationManager().scheduleMigration(migration);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            for (HazelcastInstance instance : factory.getAllHazelcastInstances()) {
                InternalPartitionImpl partition = getPartition(instance, migration.getPartitionId());
                assertEquals(partition.getReplicaAddress(migration.getDestinationNewReplicaIndex()), migration.getDestination());
            }
        }
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) AssertTask(com.hazelcast.test.AssertTask) ExpectedRuntimeException(com.hazelcast.test.ExpectedRuntimeException)

Example 43 with HazelcastInstance

use of com.hazelcast.core.HazelcastInstance in project hazelcast by hazelcast.

the class MigrationCommitServiceTest method setup.

@Before
public void setup() throws Exception {
    blockMigrationStartLatch = new CountDownLatch(1);
    factory = createHazelcastInstanceFactory(NODE_COUNT);
    instances = factory.newInstances(createConfig(), NODE_COUNT);
    warmUpPartitions(instances);
    waitAllForSafeState(instances);
    InternalOperationService operationService = getOperationService(instances[0]);
    for (int partitionId = 0; partitionId < PARTITION_COUNT; partitionId++) {
        operationService.invokeOnPartition(null, new TestIncrementOperation(), partitionId).get();
    }
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            for (int partitionId = 0; partitionId < PARTITION_COUNT; partitionId++) {
                InternalPartitionService partitionService = getPartitionService(instances[0]);
                InternalPartition partition = partitionService.getPartition(partitionId);
                for (int i = 0; i <= BACKUP_COUNT; i++) {
                    Address replicaAddress = partition.getReplicaAddress(i);
                    if (replicaAddress != null) {
                        TestMigrationAwareService service = getService(replicaAddress);
                        assertNotNull(service.get(partitionId));
                    }
                }
            }
        }
    });
    for (HazelcastInstance instance : instances) {
        TestMigrationAwareService service = getNodeEngineImpl(instance).getService(TestMigrationAwareService.SERVICE_NAME);
        service.clearEvents();
    }
}
Also used : TestMigrationAwareService(com.hazelcast.internal.partition.service.TestMigrationAwareService) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Address(com.hazelcast.nio.Address) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) AssertTask(com.hazelcast.test.AssertTask) TestIncrementOperation(com.hazelcast.internal.partition.service.TestIncrementOperation) InternalOperationService(com.hazelcast.spi.impl.operationservice.InternalOperationService) InternalPartition(com.hazelcast.internal.partition.InternalPartition) CountDownLatch(java.util.concurrent.CountDownLatch) ExpectedRuntimeException(com.hazelcast.test.ExpectedRuntimeException) Before(org.junit.Before)

Example 44 with HazelcastInstance

use of com.hazelcast.core.HazelcastInstance in project hazelcast by hazelcast.

the class MigrationCommitServiceTest method clearReplicaIndex.

private Address clearReplicaIndex(final int partitionId, int replicaIndexToClear) {
    final InternalPartitionServiceImpl partitionService = (InternalPartitionServiceImpl) getPartitionService(instances[0]);
    InternalPartitionImpl partition = (InternalPartitionImpl) partitionService.getPartition(partitionId);
    final Address oldReplicaOwner = partition.getReplicaAddress(replicaIndexToClear);
    partition.setReplicaAddress(replicaIndexToClear, null);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertTrue(partitionService.syncPartitionRuntimeState());
        }
    });
    HazelcastInstance oldReplicaOwnerInstance = factory.getInstance(oldReplicaOwner);
    ClearReplicaRunnable op = new ClearReplicaRunnable(partitionId, getNodeEngineImpl(oldReplicaOwnerInstance));
    getOperationService(oldReplicaOwnerInstance).execute(op);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            long[] replicaVersions = getReplicaVersions(factory.getInstance(oldReplicaOwner), partitionId);
            assertArrayEquals(new long[InternalPartition.MAX_BACKUP_COUNT], replicaVersions);
        }
    });
    TestMigrationAwareService migrationAwareService = getService(oldReplicaOwner);
    migrationAwareService.clearPartitionReplica(partitionId);
    for (HazelcastInstance instance : instances) {
        TestMigrationAwareService service = getNodeEngineImpl(instance).getService(TestMigrationAwareService.SERVICE_NAME);
        service.clearEvents();
    }
    return oldReplicaOwner;
}
Also used : TestMigrationAwareService(com.hazelcast.internal.partition.service.TestMigrationAwareService) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Address(com.hazelcast.nio.Address) AssertTask(com.hazelcast.test.AssertTask) ExpectedRuntimeException(com.hazelcast.test.ExpectedRuntimeException)

Example 45 with HazelcastInstance

use of com.hazelcast.core.HazelcastInstance in project hazelcast by hazelcast.

the class AbstractGracefulShutdownCorrectnessTest method testPartitionData_whenNodesShutdown.

@Test(timeout = 6000 * 10 * 10)
public void testPartitionData_whenNodesShutdown() throws InterruptedException {
    Config config = getConfig(true, false);
    HazelcastInstance hz = factory.newHazelcastInstance(config);
    startNodes(config, nodeCount);
    warmUpPartitions(factory.getAllHazelcastInstances());
    fillData(hz);
    assertSizeAndDataEventually();
    shutdownNodes(shutdownNodeCount);
    assertSizeAndData();
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) Test(org.junit.Test)

Aggregations

HazelcastInstance (com.hazelcast.core.HazelcastInstance)2084 Test (org.junit.Test)1684 QuickTest (com.hazelcast.test.annotation.QuickTest)1466 ParallelTest (com.hazelcast.test.annotation.ParallelTest)1389 Config (com.hazelcast.config.Config)815 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)665 AssertTask (com.hazelcast.test.AssertTask)263 MapConfig (com.hazelcast.config.MapConfig)254 CountDownLatch (java.util.concurrent.CountDownLatch)251 NightlyTest (com.hazelcast.test.annotation.NightlyTest)230 MapStoreConfig (com.hazelcast.config.MapStoreConfig)169 IMap (com.hazelcast.core.IMap)149 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)144 ClientConfig (com.hazelcast.client.config.ClientConfig)137 Before (org.junit.Before)111 NearCacheConfig (com.hazelcast.config.NearCacheConfig)106 Member (com.hazelcast.core.Member)99 Map (java.util.Map)96 SlowTest (com.hazelcast.test.annotation.SlowTest)94 SqlPredicate (com.hazelcast.query.SqlPredicate)83