use of com.hazelcast.client.util.AbstractLoadBalancer 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.client.util.AbstractLoadBalancer 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.client.util.AbstractLoadBalancer 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());
}
Aggregations