use of com.hazelcast.client.util.StaticLB in project hazelcast by hazelcast.
the class ClientStaticLBTest method testStaticLB_withMembers.
@Test
public void testStaticLB_withMembers() {
TestHazelcastInstanceFactory factory = new TestHazelcastInstanceFactory();
HazelcastInstance server = factory.newHazelcastInstance();
Member member = server.getCluster().getLocalMember();
StaticLB lb = new StaticLB(member);
Member nextMember = lb.next();
assertEquals(member, nextMember);
factory.terminateAll();
}
use of com.hazelcast.client.util.StaticLB in project hazelcast by hazelcast.
the class ClientMapWithIndexCreationTest method test_createMapWithIndexes_whenProxyCreatedOnMemberOtherThanClientOwner.
/**
* Given a two members (A, B) cluster, a non-smart client connected to B attempts to create a map proxy targeting member A.
*/
@Test
public void test_createMapWithIndexes_whenProxyCreatedOnMemberOtherThanClientOwner() {
Config config = new XmlConfigBuilder().build();
MapConfig mapConfig = config.getMapConfig("test");
List<MapIndexConfig> mapIndexConfigs = mapConfig.getMapIndexConfigs();
MapIndexConfig mapIndexConfig = new MapIndexConfig();
mapIndexConfig.setAttribute("name");
mapIndexConfig.setOrdered(true);
mapIndexConfigs.add(mapIndexConfig);
HazelcastInstance hz1 = factory.newHazelcastInstance(config);
HazelcastInstance hz2 = factory.newHazelcastInstance(config);
ClientConfig clientConfig = new ClientConfig();
// ProxyManager#findNextAddressToSendCreateRequest uses the configured load balancer to find the next address
// to which proxy creation request will be sent. We want this to be member hz1.
clientConfig.setLoadBalancer(new StaticLB((Member) hz1.getLocalEndpoint()));
clientConfig.getNetworkConfig().setSmartRouting(false);
// the client only connects to member hz2.
clientConfig.getNetworkConfig().addAddress(hz2.getCluster().getLocalMember().getAddress().getHost() + ":" + hz2.getCluster().getLocalMember().getAddress().getPort());
HazelcastInstance client = factory.newHazelcastClient(clientConfig);
IMap<String, SampleObjects.Employee> test = client.getMap("test");
test.put("foo", new SampleObjects.Employee(1, "name", "age", 32, true, 230));
}
Aggregations