Search in sources :

Example 66 with Member

use of com.hazelcast.core.Member in project hazelcast-simulator by hazelcast.

the class HazelcastTestUtils method nextKeyOwnedBy.

/**
 * Returns the next {@code long} key owned by the given Hazelcast instance.
 *
 * @param instance Hazelcast instance to search next key for
 * @param lastKey  last key to start search from
 * @return next key owned by given Hazelcast instance
 */
public static long nextKeyOwnedBy(HazelcastInstance instance, long lastKey) {
    Member localMember = instance.getCluster().getLocalMember();
    PartitionService partitionService = instance.getPartitionService();
    while (true) {
        Partition partition = partitionService.getPartition(lastKey);
        if (localMember.equals(partition.getOwner())) {
            return lastKey;
        }
        lastKey++;
    }
}
Also used : Partition(com.hazelcast.core.Partition) PartitionService(com.hazelcast.core.PartitionService) Member(com.hazelcast.core.Member)

Example 67 with Member

use of com.hazelcast.core.Member in project hazelcast-simulator by hazelcast.

the class HazelcastUtilsTest method testGetHazelcastAddress_withMemberWorker.

@Test
public void testGetHazelcastAddress_withMemberWorker() {
    Member member = mock(Member.class);
    when(member.getSocketAddress()).thenReturn(SOCKET_ADDRESS);
    hazelcastInstance = createMockHazelcastInstance(member);
    String address = getHazelcastAddress("member", "172.16.16.1", hazelcastInstance);
    assertEquals("127.0.0.1:5701", address);
}
Also used : HazelcastUtils.isOldestMember(com.hazelcast.simulator.utils.HazelcastUtils.isOldestMember) Member(com.hazelcast.core.Member) Test(org.junit.Test)

Example 68 with Member

use of com.hazelcast.core.Member in project hazelcast-simulator by hazelcast.

the class HazelcastUtilsTest method testGetHazelcastAddress_withMemberWorker_oldHazelcastVersion.

@Test
public void testGetHazelcastAddress_withMemberWorker_oldHazelcastVersion() {
    Member member = mock(Member.class);
    when(member.getInetSocketAddress()).thenReturn(SOCKET_ADDRESS);
    when(member.getSocketAddress()).thenThrow(new NoSuchMethodError("expected exception"));
    hazelcastInstance = createMockHazelcastInstance(member);
    String address = getHazelcastAddress("member", "172.16.16.1", hazelcastInstance);
    assertEquals("127.0.0.1:5701", address);
}
Also used : HazelcastUtils.isOldestMember(com.hazelcast.simulator.utils.HazelcastUtils.isOldestMember) Member(com.hazelcast.core.Member) Test(org.junit.Test)

Example 69 with Member

use of com.hazelcast.core.Member in project hazelcast-simulator by hazelcast.

the class HazelcastUtilsTest method createMockHazelcastInstance.

private HazelcastInstance createMockHazelcastInstance(Member member, boolean returnMember, Exception getClusterException) {
    Set<Member> memberSet = new HashSet<Member>();
    memberSet.add(member);
    Cluster cluster = mock(Cluster.class);
    when(cluster.getMembers()).thenReturn(memberSet);
    when(cluster.getLocalMember()).thenReturn(returnMember ? member : null);
    HazelcastInstance hazelcastInstance = mock(HazelcastInstance.class);
    when(hazelcastInstance.getLocalEndpoint()).thenReturn(returnMember ? member : null);
    if (getClusterException == null) {
        when(hazelcastInstance.getCluster()).thenReturn(cluster);
    } else {
        when(hazelcastInstance.getCluster()).thenReturn(cluster).thenThrow(getClusterException);
    }
    return hazelcastInstance;
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Cluster(com.hazelcast.core.Cluster) HazelcastUtils.isOldestMember(com.hazelcast.simulator.utils.HazelcastUtils.isOldestMember) Member(com.hazelcast.core.Member) HashSet(java.util.HashSet)

Example 70 with Member

use of com.hazelcast.core.Member in project hazelcast-jet by hazelcast.

the class BackpressureTest method testBackpressure.

@Test
public void testBackpressure() throws Exception {
    DAG dag = new DAG();
    final int member1Port = jet1.getCluster().getLocalMember().getAddress().getPort();
    final Member member2 = jet2.getCluster().getLocalMember();
    final int ptionOwnedByMember2 = jet1.getHazelcastInstance().getPartitionService().getPartitions().stream().filter(p -> p.getOwner().equals(member2)).map(Partition::getPartitionId).findAny().orElseThrow(() -> new RuntimeException("Can't find a partition owned by member " + jet2));
    Vertex source = dag.newVertex("source", ProcessorMetaSupplier.of((Address address) -> ProcessorSupplier.of(address.getPort() == member1Port ? GenerateP::new : noopP())));
    Vertex hiccup = dag.newVertex("hiccup", HiccupP::new);
    Vertex sink = dag.newVertex("sink", SinkProcessors.writeMapP("counts"));
    dag.edge(between(source, hiccup).distributed().partitioned(wholeItem(), (x, y) -> ptionOwnedByMember2)).edge(between(hiccup, sink));
    jet1.newJob(dag).join();
    assertCounts(jet1.getMap("counts"));
}
Also used : AbstractProcessor(com.hazelcast.jet.core.AbstractProcessor) Traverser(com.hazelcast.jet.Traverser) JetInstance(com.hazelcast.jet.JetInstance) NANOSECONDS(java.util.concurrent.TimeUnit.NANOSECONDS) RunWith(org.junit.runner.RunWith) Address(com.hazelcast.nio.Address) HashMap(java.util.HashMap) Partition(com.hazelcast.core.Partition) HazelcastSerialClassRunner(com.hazelcast.test.HazelcastSerialClassRunner) DistributedFunctions.wholeItem(com.hazelcast.jet.function.DistributedFunctions.wholeItem) Traversers.lazy(com.hazelcast.jet.Traversers.lazy) Traversers.traverseIterable(com.hazelcast.jet.Traversers.traverseIterable) Util.entry(com.hazelcast.jet.Util.entry) Map(java.util.Map) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) DAG(com.hazelcast.jet.core.DAG) Nonnull(javax.annotation.Nonnull) ProcessorSupplier(com.hazelcast.jet.core.ProcessorSupplier) Before(org.junit.Before) JetConfig(com.hazelcast.jet.config.JetConfig) NightlyTest(com.hazelcast.test.annotation.NightlyTest) JetTestSupport(com.hazelcast.jet.core.JetTestSupport) Assert.assertNotNull(org.junit.Assert.assertNotNull) ProcessorMetaSupplier(com.hazelcast.jet.core.ProcessorMetaSupplier) Test(org.junit.Test) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Category(org.junit.experimental.categories.Category) Member(com.hazelcast.core.Member) Vertex(com.hazelcast.jet.core.Vertex) SinkProcessors(com.hazelcast.jet.core.processor.SinkProcessors) Entry(java.util.Map.Entry) Processors.noopP(com.hazelcast.jet.core.processor.Processors.noopP) Assert.assertEquals(org.junit.Assert.assertEquals) Edge.between(com.hazelcast.jet.core.Edge.between) Partition(com.hazelcast.core.Partition) Vertex(com.hazelcast.jet.core.Vertex) Address(com.hazelcast.nio.Address) DAG(com.hazelcast.jet.core.DAG) Member(com.hazelcast.core.Member) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Aggregations

Member (com.hazelcast.core.Member)167 Test (org.junit.Test)43 Address (com.hazelcast.nio.Address)39 HazelcastInstance (com.hazelcast.core.HazelcastInstance)37 QuickTest (com.hazelcast.test.annotation.QuickTest)30 ParallelTest (com.hazelcast.test.annotation.ParallelTest)26 HashMap (java.util.HashMap)21 ArrayList (java.util.ArrayList)20 Config (com.hazelcast.config.Config)18 HashSet (java.util.HashSet)18 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)17 Future (java.util.concurrent.Future)17 Data (com.hazelcast.nio.serialization.Data)13 Operation (com.hazelcast.spi.Operation)13 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)13 CacheEventData (com.hazelcast.cache.impl.CacheEventData)12 HeapData (com.hazelcast.internal.serialization.impl.HeapData)12 DefaultQueryCacheEventData (com.hazelcast.map.impl.querycache.event.DefaultQueryCacheEventData)12 QueryCacheEventData (com.hazelcast.map.impl.querycache.event.QueryCacheEventData)12 OperationService (com.hazelcast.spi.OperationService)12