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