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());
}
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();
}
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());
}
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();
}
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));
}
}
Aggregations