use of org.apache.geode.distributed.internal.membership.InternalDistributedMember in project geode by apache.
the class JGroupsMessengerJUnitTest method testJChannelError.
@Test
public void testJChannelError() throws Exception {
for (int i = 0; i < 2; i++) {
boolean enableMcast = (i == 1);
initMocks(enableMcast);
JChannel mockChannel = mock(JChannel.class);
when(mockChannel.isConnected()).thenReturn(true);
doThrow(new RuntimeException()).when(mockChannel).send(any(Message.class));
JChannel realChannel = messenger.myChannel;
messenger.myChannel = mockChannel;
try {
InternalDistributedMember mbr = createAddress(8888);
DistributedCacheOperation.CacheOperationMessage msg = mock(DistributedCacheOperation.CacheOperationMessage.class);
when(msg.getRecipients()).thenReturn(new InternalDistributedMember[] { mbr });
when(msg.getMulticast()).thenReturn(enableMcast);
when(msg.getProcessorId()).thenReturn(1234);
when(msg.getDSFID()).thenReturn((int) DataSerializableFixedID.PUT_ALL_MESSAGE);
try {
messenger.send(msg);
fail("expected a failure");
} catch (DistributedSystemDisconnectedException e) {
// success
}
verify(mockChannel).send(isA(Message.class));
} finally {
messenger.myChannel = realChannel;
}
}
}
use of org.apache.geode.distributed.internal.membership.InternalDistributedMember in project geode by apache.
the class JGroupsMessengerJUnitTest method doTestBigMessageIsFragmented.
public void doTestBigMessageIsFragmented(boolean mcastEnabled, boolean mcastMsg) throws Exception {
initMocks(mcastEnabled);
MessageHandler mh = mock(MessageHandler.class);
messenger.addHandler(JoinRequestMessage.class, mh);
InternalDistributedMember sender = messenger.getMemberID();
NetView v = new NetView(sender);
when(joinLeave.getView()).thenReturn(v);
messenger.installView(v);
JoinRequestMessage msg = new JoinRequestMessage(messenger.localAddress, sender, null, -1, 0);
if (mcastMsg) {
msg.setMulticast(true);
}
messenger.send(msg);
int sentMessages = (mcastEnabled && mcastMsg) ? interceptor.mcastSentDataMessages : interceptor.unicastSentDataMessages;
assertTrue("expected 1 message to be sent but found " + sentMessages, sentMessages == 1);
// send a big message and expect fragmentation
msg = new JoinRequestMessage(messenger.localAddress, sender, new byte[(int) (services.getConfig().getDistributionConfig().getUdpFragmentSize() * (1.5))], -1, 0);
// configure an incoming message handler for JoinRequestMessage
final DistributionMessage[] messageReceived = new DistributionMessage[1];
MessageHandler handler = new MessageHandler() {
@Override
public void processMessage(DistributionMessage m) {
messageReceived[0] = m;
}
};
messenger.addHandler(JoinRequestMessage.class, handler);
// configure the outgoing message interceptor
interceptor.unicastSentDataMessages = 0;
interceptor.collectMessages = true;
interceptor.collectedMessages.clear();
messenger.send(msg);
assertTrue("expected 2 messages to be sent but found " + interceptor.unicastSentDataMessages, interceptor.unicastSentDataMessages == 2);
List<Message> messages = new ArrayList<>(interceptor.collectedMessages);
UUID fakeMember = new UUID(50, 50);
short unicastHeaderId = ClassConfigurator.getProtocolId(UNICAST3.class);
int seqno = 1;
for (Message m : messages) {
m.setSrc(fakeMember);
UNICAST3.Header oldHeader = (UNICAST3.Header) m.getHeader(unicastHeaderId);
if (oldHeader == null)
continue;
UNICAST3.Header newHeader = UNICAST3.Header.createDataHeader(seqno, oldHeader.connId(), seqno == 1);
seqno += 1;
m.putHeader(unicastHeaderId, newHeader);
interceptor.up(new Event(Event.MSG, m));
}
Thread.sleep(5000);
System.out.println("received message = " + messageReceived[0]);
}
use of org.apache.geode.distributed.internal.membership.InternalDistributedMember in project geode by apache.
the class GMSMembershipManagerJUnitTest method initMocks.
@Before
public void initMocks() throws Exception {
Properties nonDefault = new Properties();
nonDefault.put(ACK_WAIT_THRESHOLD, "1");
nonDefault.put(ACK_SEVERE_ALERT_THRESHOLD, "10");
nonDefault.put(DISABLE_TCP, "true");
nonDefault.put(MCAST_PORT, "0");
nonDefault.put(MCAST_TTL, "0");
nonDefault.put(LOG_FILE, "");
nonDefault.put(LOG_LEVEL, "fine");
nonDefault.put(MEMBER_TIMEOUT, "2000");
nonDefault.put(LOCATORS, "localhost[10344]");
distConfig = new DistributionConfigImpl(nonDefault);
distProperties = nonDefault;
RemoteTransportConfig tconfig = new RemoteTransportConfig(distConfig, DistributionManager.NORMAL_DM_TYPE);
mockConfig = mock(ServiceConfig.class);
when(mockConfig.getDistributionConfig()).thenReturn(distConfig);
when(mockConfig.getTransport()).thenReturn(tconfig);
authenticator = mock(Authenticator.class);
myMemberId = new InternalDistributedMember("localhost", 8887);
messenger = mock(Messenger.class);
when(messenger.getMemberID()).thenReturn(myMemberId);
stopper = mock(Stopper.class);
when(stopper.isCancelInProgress()).thenReturn(false);
healthMonitor = mock(HealthMonitor.class);
when(healthMonitor.getFailureDetectionPort()).thenReturn(Integer.valueOf(-1));
joinLeave = mock(JoinLeave.class);
services = mock(Services.class);
when(services.getAuthenticator()).thenReturn(authenticator);
when(services.getConfig()).thenReturn(mockConfig);
when(services.getMessenger()).thenReturn(messenger);
when(services.getCancelCriterion()).thenReturn(stopper);
when(services.getHealthMonitor()).thenReturn(healthMonitor);
when(services.getJoinLeave()).thenReturn(joinLeave);
Timer t = new Timer(true);
when(services.getTimer()).thenReturn(t);
Random r = new Random();
mockMembers = new InternalDistributedMember[5];
for (int i = 0; i < mockMembers.length; i++) {
mockMembers[i] = new InternalDistributedMember("localhost", 8888 + i);
GMSMember m = (GMSMember) mockMembers[i].getNetMember();
UUID uuid = new UUID(r.nextLong(), r.nextLong());
m.setUUID(uuid);
}
members = new ArrayList<>(Arrays.asList(mockMembers));
listener = mock(DistributedMembershipListener.class);
manager = new GMSMembershipManager(listener);
manager.init(services);
when(services.getManager()).thenReturn(manager);
}
use of org.apache.geode.distributed.internal.membership.InternalDistributedMember in project geode by apache.
the class GMSMembershipManagerJUnitTest method testSendAdminMessageFailsDuringShutdown.
@Test
public void testSendAdminMessageFailsDuringShutdown() throws Exception {
AlertListenerMessage m = AlertListenerMessage.create(mockMembers[0], 1, new Date(System.currentTimeMillis()), "thread", "", 1L, "", "");
manager.start();
manager.started();
manager.installView(new NetView(myMemberId, 1, members));
manager.setShutdown();
Set<InternalDistributedMember> failures = manager.send(m);
verify(messenger, never()).send(m);
assertEquals(1, failures.size());
assertEquals(mockMembers[0], failures.iterator().next());
}
use of org.apache.geode.distributed.internal.membership.InternalDistributedMember in project geode by apache.
the class GMSMembershipManagerJUnitTest method testAddressesWithoutUUIDs.
/**
* This test ensures that the membership manager can accept an ID that does not have a UUID and
* replace it with one that does have a UUID from the current membership view.
*/
@Test
public void testAddressesWithoutUUIDs() throws Exception {
manager.start();
manager.started();
manager.isJoining = true;
List<InternalDistributedMember> viewmembers = Arrays.asList(new InternalDistributedMember[] { mockMembers[0], mockMembers[1], myMemberId });
manager.installView(new NetView(myMemberId, 2, viewmembers));
InternalDistributedMember[] destinations = new InternalDistributedMember[viewmembers.size()];
for (int i = 0; i < destinations.length; i++) {
InternalDistributedMember id = viewmembers.get(i);
destinations[i] = new InternalDistributedMember(id.getHost(), id.getPort());
}
manager.checkAddressesForUUIDs(destinations);
// ID from the membership view
for (int i = 0; i < destinations.length; i++) {
assertTrue(viewmembers.get(i) == destinations[i]);
}
}
Aggregations