Search in sources :

Example 1 with StaticLB

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();
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) StaticLB(com.hazelcast.client.util.StaticLB) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) Member(com.hazelcast.core.Member) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 2 with StaticLB

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));
}
Also used : XmlConfigBuilder(com.hazelcast.config.XmlConfigBuilder) MapIndexConfig(com.hazelcast.config.MapIndexConfig) SampleObjects(com.hazelcast.query.SampleObjects) Config(com.hazelcast.config.Config) MapIndexConfig(com.hazelcast.config.MapIndexConfig) MapConfig(com.hazelcast.config.MapConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) StaticLB(com.hazelcast.client.util.StaticLB) HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapConfig(com.hazelcast.config.MapConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) Member(com.hazelcast.core.Member) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

StaticLB (com.hazelcast.client.util.StaticLB)2 HazelcastInstance (com.hazelcast.core.HazelcastInstance)2 Member (com.hazelcast.core.Member)2 ParallelTest (com.hazelcast.test.annotation.ParallelTest)2 QuickTest (com.hazelcast.test.annotation.QuickTest)2 Test (org.junit.Test)2 ClientConfig (com.hazelcast.client.config.ClientConfig)1 Config (com.hazelcast.config.Config)1 MapConfig (com.hazelcast.config.MapConfig)1 MapIndexConfig (com.hazelcast.config.MapIndexConfig)1 XmlConfigBuilder (com.hazelcast.config.XmlConfigBuilder)1 SampleObjects (com.hazelcast.query.SampleObjects)1 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)1