Search in sources :

Example 76 with AssertTask

use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.

the class ShutdownClusterRequestTest method testShutdownCluster.

@Test
public void testShutdownCluster() throws Exception {
    ShutdownClusterRequest request = new ShutdownClusterRequest();
    cluster.getClusterState();
    JsonObject jsonObject = new JsonObject();
    request.writeResponse(managementCenterService, jsonObject);
    JsonObject result = (JsonObject) jsonObject.get("result");
    assertEquals("SUCCESS", request.readResponse(result));
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertFalse(lifecycleService.isRunning());
        }
    });
}
Also used : JsonObject(com.eclipsesource.json.JsonObject) AssertTask(com.hazelcast.test.AssertTask) ShutdownClusterRequest(com.hazelcast.internal.management.request.ShutdownClusterRequest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 77 with AssertTask

use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.

the class RestClusterTest method testClusterShutdown.

@Test
public void testClusterShutdown() throws Exception {
    final HazelcastInstance instance1 = Hazelcast.newHazelcastInstance(config);
    final HazelcastInstance instance2 = Hazelcast.newHazelcastInstance(config);
    HTTPCommunicator communicator = new HTTPCommunicator(instance2);
    assertEquals(HttpURLConnection.HTTP_OK, communicator.shutdownCluster("dev", "dev-pass"));
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertFalse(instance1.getLifecycleService().isRunning());
            assertFalse(instance2.getLifecycleService().isRunning());
        }
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) AssertTask(com.hazelcast.test.AssertTask) SocketException(java.net.SocketException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 78 with AssertTask

use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.

the class AdvancedClusterStateTest method changeClusterState_shouldNotFail_whenNonInitiatorMemberDies_duringCommit.

@Test
public void changeClusterState_shouldNotFail_whenNonInitiatorMemberDies_duringCommit() throws Exception {
    final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
    final HazelcastInstance[] instances = factory.newInstances();
    final HazelcastInstance hz = instances[2];
    TransactionManagerServiceImpl transactionManagerService = spyTransactionManagerService(hz);
    final Address address = getAddress(instances[0]);
    TransactionOptions options = TransactionOptions.getDefault().setDurability(0);
    when(transactionManagerService.newAllowedDuringPassiveStateTransaction(options)).thenAnswer(new TransactionAnswer() {

        @Override
        protected void afterPrepare() {
            terminateInstance(instances[0]);
        }
    });
    hz.getCluster().changeClusterState(ClusterState.FROZEN, options);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertClusterState(ClusterState.FROZEN, instances[2], instances[1]);
        }
    });
    instances[0] = factory.newHazelcastInstance(address);
    assertClusterSizeEventually(3, instances[0]);
    assertClusterSizeEventually(3, instances[1]);
    assertClusterSizeEventually(3, instances[2]);
    assertClusterState(ClusterState.FROZEN, instances);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Address(com.hazelcast.nio.Address) TransactionManagerServiceImpl(com.hazelcast.transaction.impl.TransactionManagerServiceImpl) TransactionOptions(com.hazelcast.transaction.TransactionOptions) AssertTask(com.hazelcast.test.AssertTask) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) TargetNotMemberException(com.hazelcast.spi.exception.TargetNotMemberException) TransactionException(com.hazelcast.transaction.TransactionException) ExecutionException(java.util.concurrent.ExecutionException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 79 with AssertTask

use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.

the class BasicClusterStateTest method test_eventsDispatched_whenClusterState_PASSIVE.

@Test
public void test_eventsDispatched_whenClusterState_PASSIVE() {
    System.setProperty(EventServiceImpl.EVENT_SYNC_FREQUENCY_PROP, "1");
    final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    final HazelcastInstance master = factory.newHazelcastInstance();
    final HazelcastInstance other = factory.newHazelcastInstance();
    changeClusterStateEventually(master, ClusterState.PASSIVE);
    master.getMap(randomMapName());
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals(1, getNodeEngineImpl(other).getProxyService().getProxyCount());
        }
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) AssertTask(com.hazelcast.test.AssertTask) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 80 with AssertTask

use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.

the class LockGuardTest method testIsLeaseExpired.

@Test
public void testIsLeaseExpired() throws Exception {
    LockGuard stateLock = LockGuard.NOT_LOCKED;
    assertFalse(stateLock.isLeaseExpired());
    Address endpoint = newAddress();
    stateLock = new LockGuard(endpoint, "txn", TimeUnit.HOURS.toMillis(1));
    assertFalse(stateLock.isLeaseExpired());
    stateLock = new LockGuard(endpoint, "txn", 1);
    final LockGuard finalStateLock = stateLock;
    HazelcastTestSupport.assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertTrue(finalStateLock.isLeaseExpired());
        }
    });
}
Also used : Address(com.hazelcast.nio.Address) InetAddress(java.net.InetAddress) AssertTask(com.hazelcast.test.AssertTask) UnknownHostException(java.net.UnknownHostException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

AssertTask (com.hazelcast.test.AssertTask)575 Test (org.junit.Test)489 QuickTest (com.hazelcast.test.annotation.QuickTest)428 ParallelTest (com.hazelcast.test.annotation.ParallelTest)347 HazelcastInstance (com.hazelcast.core.HazelcastInstance)263 Config (com.hazelcast.config.Config)113 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)94 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)75 ExecutionException (java.util.concurrent.ExecutionException)57 MapConfig (com.hazelcast.config.MapConfig)49 NightlyTest (com.hazelcast.test.annotation.NightlyTest)48 IOException (java.io.IOException)46 CountDownLatch (java.util.concurrent.CountDownLatch)42 IMap (com.hazelcast.core.IMap)39 NearCacheConfig (com.hazelcast.config.NearCacheConfig)38 TimeoutException (java.util.concurrent.TimeoutException)33 ClientConfig (com.hazelcast.client.config.ClientConfig)32 MapStoreConfig (com.hazelcast.config.MapStoreConfig)29 ExpectedRuntimeException (com.hazelcast.test.ExpectedRuntimeException)23 AtomicReference (java.util.concurrent.atomic.AtomicReference)20