Search in sources :

Example 1 with Member

use of com.hazelcast.cluster.Member in project hazelcast by hazelcast.

the class ClientUniSocketTxnTest method testUniSocketClient_shouldNotOpenANewConnection.

@Test
public void testUniSocketClient_shouldNotOpenANewConnection() {
    hazelcastFactory.newHazelcastInstance();
    ClientConfig config = new ClientConfig();
    config.getNetworkConfig().setRedoOperation(true);
    config.getNetworkConfig().setSmartRouting(false);
    // try to force second member to connect when exist
    config.setLoadBalancer(new AbstractLoadBalancer() {

        @Override
        public Member next() {
            Member[] members = getMembers();
            if (members == null || members.length == 0) {
                return null;
            }
            if (members.length == 2) {
                return members[1];
            }
            return members[0];
        }

        @Override
        public Member nextDataMember() {
            Member[] members = getDataMembers();
            if (members == null || members.length == 0) {
                return null;
            }
            if (members.length == 2) {
                return members[1];
            }
            return members[0];
        }

        @Override
        public boolean canGetNextDataMember() {
            return true;
        }
    });
    final HazelcastInstance client = hazelcastFactory.newHazelcastClient(config);
    hazelcastFactory.newHazelcastInstance();
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals(2, client.getCluster().getMembers().size());
        }
    });
    ClientConnectionManager connectionManager = getHazelcastClientInstanceImpl(client).getConnectionManager();
    TransactionContext context = client.newTransactionContext();
    context.beginTransaction();
    context.commitTransaction();
    assertEquals(1, connectionManager.getActiveConnections().size());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) TransactionContext(com.hazelcast.transaction.TransactionContext) AssertTask(com.hazelcast.test.AssertTask) ClientConfig(com.hazelcast.client.config.ClientConfig) AbstractLoadBalancer(com.hazelcast.client.util.AbstractLoadBalancer) Member(com.hazelcast.cluster.Member) ClientConnectionManager(com.hazelcast.client.impl.connection.ClientConnectionManager) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with Member

use of com.hazelcast.cluster.Member in project hazelcast by hazelcast.

the class ClientTxnTest method setup.

@Before
public void setup() {
    server = hazelcastFactory.newHazelcastInstance();
    final ClientConfig config = new ClientConfig();
    config.getNetworkConfig().setRedoOperation(true);
    // always start the txn on first member
    config.setLoadBalancer(new AbstractLoadBalancer() {

        @Override
        public Member next() {
            Member[] members = getMembers();
            if (members == null || members.length == 0) {
                return null;
            }
            return members[0];
        }

        @Override
        public Member nextDataMember() {
            Member[] members = getDataMembers();
            if (members == null || members.length == 0) {
                return null;
            }
            return members[0];
        }

        @Override
        public boolean canGetNextDataMember() {
            return true;
        }
    });
    client = hazelcastFactory.newHazelcastClient(config);
    hazelcastFactory.newHazelcastInstance();
}
Also used : ClientConfig(com.hazelcast.client.config.ClientConfig) AbstractLoadBalancer(com.hazelcast.client.util.AbstractLoadBalancer) Member(com.hazelcast.cluster.Member) Before(org.junit.Before)

Example 3 with Member

use of com.hazelcast.cluster.Member in project hazelcast by hazelcast.

the class ClientTxnUniSocketTest method testUniSocketClient_shouldNotOpenANewConnection.

@Test
public void testUniSocketClient_shouldNotOpenANewConnection() {
    hazelcastFactory.newHazelcastInstance();
    ClientConfig config = new ClientConfig();
    config.getNetworkConfig().setRedoOperation(true);
    config.getNetworkConfig().setSmartRouting(false);
    // try to force second member to connect when exist
    config.setLoadBalancer(new AbstractLoadBalancer() {

        @Override
        public Member next() {
            Member[] members = getMembers();
            if (members == null || members.length == 0) {
                return null;
            }
            if (members.length == 2) {
                return members[1];
            }
            return members[0];
        }

        @Override
        public Member nextDataMember() {
            Member[] members = getDataMembers();
            if (members == null || members.length == 0) {
                return null;
            }
            if (members.length == 2) {
                return members[1];
            }
            return members[0];
        }

        @Override
        public boolean canGetNextDataMember() {
            return true;
        }
    });
    final HazelcastInstance client = hazelcastFactory.newHazelcastClient(config);
    hazelcastFactory.newHazelcastInstance();
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals(2, client.getCluster().getMembers().size());
        }
    });
    ClientConnectionManager connectionManager = getHazelcastClientInstanceImpl(client).getConnectionManager();
    TransactionContext context = client.newTransactionContext();
    context.beginTransaction();
    context.commitTransaction();
    assertEquals(1, connectionManager.getActiveConnections().size());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) TransactionContext(com.hazelcast.transaction.TransactionContext) AssertTask(com.hazelcast.test.AssertTask) ClientConfig(com.hazelcast.client.config.ClientConfig) AbstractLoadBalancer(com.hazelcast.client.util.AbstractLoadBalancer) Member(com.hazelcast.cluster.Member) ClientConnectionManager(com.hazelcast.client.impl.connection.ClientConnectionManager) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with Member

use of com.hazelcast.cluster.Member in project hazelcast by hazelcast.

the class MapPutPartitionAwareCallable method call.

@Override
public T call() throws Exception {
    Member member = instance.getCluster().getLocalMember();
    IMap<UUID, String> map = instance.getMap(mapName);
    map.put(member.getUuid(), member.getUuid() + "value");
    return (T) member.getUuid();
}
Also used : UUID(java.util.UUID) Member(com.hazelcast.cluster.Member)

Example 5 with Member

use of com.hazelcast.cluster.Member in project hazelcast by hazelcast.

the class TransactionListTest method testMigrationSerializationNotFails_whenTransactionsAreUsed.

@Test
public void testMigrationSerializationNotFails_whenTransactionsAreUsed() throws Exception {
    Config config = new Config();
    config.setProperty("hazelcast.partition.count", "2");
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance instance1 = factory.newHazelcastInstance(config);
    String listName = randomString();
    TransactionContext tr = instance1.newTransactionContext();
    tr.beginTransaction();
    TransactionalList<Object> list = tr.getList(listName);
    for (int i = 0; i < 10; i++) {
        list.add(i);
    }
    tr.commitTransaction();
    HazelcastInstance instance2 = factory.newHazelcastInstance(config);
    Member owner = instance1.getPartitionService().getPartition(listName).getOwner();
    HazelcastInstance aliveInstance;
    if (instance1.getCluster().getLocalMember().equals(owner)) {
        instance1.shutdown();
        aliveInstance = instance2;
    } else {
        instance2.shutdown();
        aliveInstance = instance1;
    }
    IList<Object> l = aliveInstance.getList(listName);
    for (int i = 0; i < 10; i++) {
        assertEquals(i, l.get(i));
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) TransactionContext(com.hazelcast.transaction.TransactionContext) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) Member(com.hazelcast.cluster.Member) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

Member (com.hazelcast.cluster.Member)429 Test (org.junit.Test)210 QuickTest (com.hazelcast.test.annotation.QuickTest)191 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)164 HazelcastInstance (com.hazelcast.core.HazelcastInstance)116 IExecutorService (com.hazelcast.core.IExecutorService)73 Address (com.hazelcast.cluster.Address)62 ArrayList (java.util.ArrayList)55 Future (java.util.concurrent.Future)53 UUID (java.util.UUID)43 Config (com.hazelcast.config.Config)42 CountDownLatch (java.util.concurrent.CountDownLatch)38 Map (java.util.Map)33 HashMap (java.util.HashMap)31 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)28 MultiExecutionCallback (com.hazelcast.core.MultiExecutionCallback)25 List (java.util.List)25 MemberImpl (com.hazelcast.cluster.impl.MemberImpl)24 Operation (com.hazelcast.spi.impl.operationservice.Operation)24 IMap (com.hazelcast.map.IMap)23