Search in sources :

Example 16 with Version

use of com.hazelcast.version.Version in project hazelcast by hazelcast.

the class DefaultNodeExtensionTest method test_clusterVersionListener_invokedWithNodeCodebaseVersion_whenClusterVersionIsNull.

@Test
public void test_clusterVersionListener_invokedWithNodeCodebaseVersion_whenClusterVersionIsNull() throws UnknownHostException, NoSuchFieldException, IllegalAccessException {
    final CountDownLatch latch = new CountDownLatch(1);
    final AtomicBoolean failed = new AtomicBoolean(false);
    ClusterVersionListener listener = new ClusterVersionListener() {

        @Override
        public void onClusterVersionChange(Version newVersion) {
            if (!newVersion.equals(node.getVersion().asVersion())) {
                failed.set(true);
            }
            latch.countDown();
        }
    };
    makeClusterVersionUnknownAndVerifyListener(latch, failed, listener);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Version(com.hazelcast.version.Version) MemberVersion(com.hazelcast.version.MemberVersion) CountDownLatch(java.util.concurrent.CountDownLatch) ClusterVersionListener(com.hazelcast.internal.cluster.ClusterVersionListener) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 17 with Version

use of com.hazelcast.version.Version in project hazelcast by hazelcast.

the class ClusterStateManager method commitClusterState.

public void commitClusterState(ClusterStateChange stateChange, Address initiator, String txnId, boolean isTransient) {
    Preconditions.checkNotNull(stateChange);
    stateChange.validate();
    clusterServiceLock.lock();
    try {
        final LockGuard stateLock = getStateLock();
        if (!stateLock.allowsUnlock(txnId)) {
            throw new TransactionException("Cluster state change [" + state + " -> " + stateChange + "] failed for " + initiator + ", current state: " + stateToString());
        }
        if (stateChange.isOfType(ClusterState.class)) {
            ClusterState newState = (ClusterState) stateChange.getNewState();
            doSetClusterState(newState, isTransient);
            // if state is changed to ACTIVE, then remove all members which left while not active.
            if (newState == ClusterState.ACTIVE) {
                node.getClusterService().removeMembersDeadWhileClusterIsNotActive();
            }
        } else if (stateChange.isOfType(Version.class)) {
            // version is validated on cluster-state-lock, thus we can commit without checking compatibility
            doSetClusterVersion((Version) stateChange.getNewState());
        } else {
            throw new IllegalArgumentException("Illegal ClusterStateChange of type " + stateChange.getType() + ".");
        }
    } finally {
        clusterServiceLock.unlock();
    }
}
Also used : ClusterState(com.hazelcast.cluster.ClusterState) TransactionException(com.hazelcast.transaction.TransactionException) Version(com.hazelcast.version.Version) LockGuard(com.hazelcast.internal.util.LockGuard)

Example 18 with Version

use of com.hazelcast.version.Version in project hazelcast by hazelcast.

the class ArrayDataSerializableFactoryTest method testCreateWithVersion.

@Test
public void testCreateWithVersion() throws Exception {
    ConstructorFunction<Integer, IdentifiedDataSerializable>[] constructorFunctions = new ConstructorFunction[1];
    VersionAwareConstructorFunction function = mock(VersionAwareConstructorFunction.class);
    constructorFunctions[0] = function;
    ArrayDataSerializableFactory factory = new ArrayDataSerializableFactory(constructorFunctions);
    Version version = MemberVersion.of(3, 6, 0).asVersion();
    factory.create(0, version);
    verify(function, times(0)).createNew(0);
    verify(function, times(1)).createNew(0, version);
}
Also used : VersionAwareConstructorFunction(com.hazelcast.util.VersionAwareConstructorFunction) MemberVersion(com.hazelcast.version.MemberVersion) Version(com.hazelcast.version.Version) ConstructorFunction(com.hazelcast.util.ConstructorFunction) VersionAwareConstructorFunction(com.hazelcast.util.VersionAwareConstructorFunction) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 19 with Version

use of com.hazelcast.version.Version in project hazelcast by hazelcast.

the class VersionedObjectDataInputAndOutputTest method testVersionOnOutput.

@Test
public void testVersionOnOutput() {
    ObjectDataOutputStream output = new ObjectDataOutputStream(new ByteArrayOutputStream(16), iss);
    Version version = Versions.V3_8;
    output.setVersion(version);
    assertEquals(version, output.getVersion());
}
Also used : Version(com.hazelcast.version.Version) ByteArrayOutputStream(java.io.ByteArrayOutputStream) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 20 with Version

use of com.hazelcast.version.Version in project hazelcast by hazelcast.

the class NodeStateImplTest method toJson.

@Test
public void toJson() throws Exception {
    ClusterState clusterState = ClusterState.ACTIVE;
    com.hazelcast.instance.NodeState nodeState = com.hazelcast.instance.NodeState.PASSIVE;
    Version clusterVersion = Version.of("3.8");
    MemberVersion memberVersion = MemberVersion.of("3.9.0");
    NodeState state = new NodeStateImpl(clusterState, nodeState, clusterVersion, memberVersion);
    NodeState deserialized = new NodeStateImpl();
    deserialized.fromJson(state.toJson());
    assertEquals(clusterState, deserialized.getClusterState());
    assertEquals(nodeState, deserialized.getNodeState());
    assertEquals(clusterVersion, deserialized.getClusterVersion());
    assertEquals(memberVersion, deserialized.getMemberVersion());
}
Also used : ClusterState(com.hazelcast.cluster.ClusterState) NodeState(com.hazelcast.monitor.NodeState) MemberVersion(com.hazelcast.version.MemberVersion) Version(com.hazelcast.version.Version) MemberVersion(com.hazelcast.version.MemberVersion) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

Version (com.hazelcast.version.Version)20 ParallelTest (com.hazelcast.test.annotation.ParallelTest)17 QuickTest (com.hazelcast.test.annotation.QuickTest)17 Test (org.junit.Test)17 MemberVersion (com.hazelcast.version.MemberVersion)16 Config (com.hazelcast.config.Config)5 ExpectedException (org.junit.rules.ExpectedException)5 ClusterState (com.hazelcast.cluster.ClusterState)3 HazelcastInstance (com.hazelcast.core.HazelcastInstance)3 ClusterVersionListener (com.hazelcast.internal.cluster.ClusterVersionListener)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 CacheStatisticsImpl (com.hazelcast.cache.impl.CacheStatisticsImpl)1 GroupConfig (com.hazelcast.config.GroupConfig)1 BackupTaskStatus (com.hazelcast.hotrestart.BackupTaskStatus)1 MemberImpl (com.hazelcast.instance.MemberImpl)1 Node (com.hazelcast.instance.Node)1 ClusterService (com.hazelcast.internal.cluster.ClusterService)1 MemberInfo (com.hazelcast.internal.cluster.MemberInfo)1 AuthenticationFailureOperation (com.hazelcast.internal.cluster.impl.operations.AuthenticationFailureOperation)1 AuthorizationOperation (com.hazelcast.internal.cluster.impl.operations.AuthorizationOperation)1