use of org.apache.geode.distributed.internal.membership.gms.interfaces.JoinLeave in project geode by apache.
the class MembershipJUnitTest method doTestMultipleManagersInSameProcessWithGroups.
/**
* this runs the test with a given set of member groups. Returns the groups of the member that was
* not the coordinator for verification that they were correctly transmitted
*/
private List<String> doTestMultipleManagersInSameProcessWithGroups(String groups) throws Exception {
MembershipManager m1 = null, m2 = null;
Locator l = null;
try {
// boot up a locator
int port = AvailablePortHelper.getRandomAvailableTCPPort();
InetAddress localHost = SocketCreator.getLocalHost();
// this locator will hook itself up with the first MembershipManager
// to be created
l = InternalLocator.startLocator(port, new File(""), null, null, null, localHost, false, new Properties(), null);
// create configuration objects
Properties nonDefault = new Properties();
nonDefault.put(DISABLE_TCP, "true");
nonDefault.put(MCAST_PORT, "0");
nonDefault.put(LOG_FILE, "");
nonDefault.put(LOG_LEVEL, "fine");
nonDefault.put(GROUPS, groups);
nonDefault.put(MEMBER_TIMEOUT, "2000");
nonDefault.put(LOCATORS, localHost.getHostName() + '[' + port + ']');
DistributionConfigImpl config = new DistributionConfigImpl(nonDefault);
RemoteTransportConfig transport = new RemoteTransportConfig(config, DistributionManager.NORMAL_DM_TYPE);
// start the first membership manager
try {
System.setProperty(GMSJoinLeave.BYPASS_DISCOVERY_PROPERTY, "true");
DistributedMembershipListener listener1 = mock(DistributedMembershipListener.class);
DMStats stats1 = mock(DMStats.class);
System.out.println("creating 1st membership manager");
m1 = MemberFactory.newMembershipManager(listener1, config, transport, stats1);
m1.startEventProcessing();
} finally {
System.getProperties().remove(GMSJoinLeave.BYPASS_DISCOVERY_PROPERTY);
}
// start the second membership manager
DistributedMembershipListener listener2 = mock(DistributedMembershipListener.class);
DMStats stats2 = mock(DMStats.class);
System.out.println("creating 2nd membership manager");
m2 = MemberFactory.newMembershipManager(listener2, config, transport, stats2);
m2.startEventProcessing();
// we have to check the views with JoinLeave because the membership
// manager queues new views for processing through the DM listener,
// which is a mock object in this test
System.out.println("waiting for views to stabilize");
JoinLeave jl1 = ((GMSMembershipManager) m1).getServices().getJoinLeave();
JoinLeave jl2 = ((GMSMembershipManager) m2).getServices().getJoinLeave();
long giveUp = System.currentTimeMillis() + 15000;
for (; ; ) {
try {
assertTrue("view = " + jl2.getView(), jl2.getView().size() == 2);
assertTrue("view = " + jl1.getView(), jl1.getView().size() == 2);
assertTrue(jl1.getView().getCreator().equals(jl2.getView().getCreator()));
assertTrue(jl1.getView().getViewId() == jl2.getView().getViewId());
break;
} catch (AssertionError e) {
if (System.currentTimeMillis() > giveUp) {
throw e;
}
}
}
NetView view = jl1.getView();
InternalDistributedMember notCreator;
if (view.getCreator().equals(jl1.getMemberID())) {
notCreator = view.getMembers().get(1);
} else {
notCreator = view.getMembers().get(0);
}
List<String> result = notCreator.getGroups();
System.out.println("sending SerialAckedMessage from m1 to m2");
SerialAckedMessage msg = new SerialAckedMessage();
msg.setRecipient(m2.getLocalMember());
msg.setMulticast(false);
m1.send(new InternalDistributedMember[] { m2.getLocalMember() }, msg, null);
giveUp = System.currentTimeMillis() + 15000;
boolean verified = false;
Throwable problem = null;
while (giveUp > System.currentTimeMillis()) {
try {
verify(listener2).messageReceived(isA(SerialAckedMessage.class));
verified = true;
break;
} catch (Error e) {
problem = e;
Thread.sleep(500);
}
}
if (!verified) {
AssertionError error = new AssertionError("Expected a message to be received");
if (problem != null) {
error.initCause(error);
}
throw error;
}
// let the managers idle for a while and get used to each other
// Thread.sleep(4000l);
m2.shutdown();
assertTrue(!m2.isConnected());
assertTrue(m1.getView().size() == 1);
return result;
} finally {
if (m2 != null) {
m2.shutdown();
}
if (m1 != null) {
m1.shutdown();
}
if (l != null) {
l.stop();
}
}
}
use of org.apache.geode.distributed.internal.membership.gms.interfaces.JoinLeave in project geode by apache.
the class JGroupsMessengerJUnitTest method initMocks.
/**
* Create stub and mock objects
*/
private void initMocks(boolean enableMcast, Properties addProp) throws Exception {
if (messenger != null) {
messenger.stop();
messenger = null;
}
Properties nonDefault = new Properties();
nonDefault.put(DISABLE_TCP, "true");
nonDefault.put(MCAST_PORT, enableMcast ? "" + AvailablePortHelper.getRandomAvailableUDPPort() : "0");
nonDefault.put(MCAST_TTL, "0");
nonDefault.put(LOG_FILE, "");
nonDefault.put(LOG_LEVEL, "fine");
nonDefault.put(LOCATORS, "localhost[10344]");
nonDefault.put(ACK_WAIT_THRESHOLD, "1");
nonDefault.putAll(addProp);
DistributionConfigImpl config = new DistributionConfigImpl(nonDefault);
RemoteTransportConfig tconfig = new RemoteTransportConfig(config, DistributionManager.NORMAL_DM_TYPE);
stopper = mock(Stopper.class);
when(stopper.isCancelInProgress()).thenReturn(false);
manager = mock(Manager.class);
when(manager.isMulticastAllowed()).thenReturn(enableMcast);
healthMonitor = mock(HealthMonitor.class);
joinLeave = mock(JoinLeave.class);
ServiceConfig serviceConfig = new ServiceConfig(tconfig, config);
services = mock(Services.class);
when(services.getConfig()).thenReturn(serviceConfig);
when(services.getCancelCriterion()).thenReturn(stopper);
when(services.getHealthMonitor()).thenReturn(healthMonitor);
when(services.getManager()).thenReturn(manager);
when(services.getJoinLeave()).thenReturn(joinLeave);
DM dm = mock(DM.class);
InternalDistributedSystem system = InternalDistributedSystem.newInstanceForTesting(dm, nonDefault);
when(services.getStatistics()).thenReturn(new DistributionStats(system, statsId));
messenger = new JGroupsMessenger();
messenger.init(services);
// if I do this earlier then test this return messenger as null
when(services.getMessenger()).thenReturn(messenger);
String jgroupsConfig = messenger.getJGroupsStackConfig();
int startIdx = jgroupsConfig.indexOf("<org");
int insertIdx = jgroupsConfig.indexOf('>', startIdx + 4) + 1;
jgroupsConfig = jgroupsConfig.substring(0, insertIdx) + "<" + InterceptUDP.class.getName() + "/>" + jgroupsConfig.substring(insertIdx);
messenger.setJGroupsStackConfigForTesting(jgroupsConfig);
// System.out.println("jgroups config: " + jgroupsConfig);
messenger.start();
messenger.started();
interceptor = (InterceptUDP) messenger.myChannel.getProtocolStack().getTransport().getUpProtocol();
}
use of org.apache.geode.distributed.internal.membership.gms.interfaces.JoinLeave 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.gms.interfaces.JoinLeave in project geode by apache.
the class MembershipJUnitTest method testLocatorAndTwoServersJoinUsingDiffeHellman.
/**
* This test ensures that secure communications are enabled.
*
* This test creates a locator with a colocated membership manager and then creates a second
* manager that joins the system of the first.
*
* It then makes assertions about the state of the membership view, closes one of the managers and
* makes more assertions.
*/
@Test
public void testLocatorAndTwoServersJoinUsingDiffeHellman() throws Exception {
MembershipManager m1 = null, m2 = null;
Locator l = null;
int mcastPort = AvailablePortHelper.getRandomAvailableUDPPort();
try {
// boot up a locator
int port = AvailablePortHelper.getRandomAvailableTCPPort();
InetAddress localHost = SocketCreator.getLocalHost();
Properties p = new Properties();
p.setProperty(ConfigurationProperties.SECURITY_UDP_DHALGO, "AES:128");
// this locator will hook itself up with the first MembershipManager
// to be created
l = InternalLocator.startLocator(port, new File(""), null, null, null, localHost, false, p, null);
// create configuration objects
Properties nonDefault = new Properties();
nonDefault.put(DistributionConfig.DISABLE_TCP_NAME, "true");
nonDefault.put(DistributionConfig.MCAST_PORT_NAME, String.valueOf(mcastPort));
nonDefault.put(DistributionConfig.LOG_FILE_NAME, "");
nonDefault.put(DistributionConfig.LOG_LEVEL_NAME, "fine");
nonDefault.put(DistributionConfig.GROUPS_NAME, "red, blue");
nonDefault.put(DistributionConfig.MEMBER_TIMEOUT_NAME, "2000");
nonDefault.put(DistributionConfig.LOCATORS_NAME, localHost.getHostName() + '[' + port + ']');
nonDefault.put(ConfigurationProperties.SECURITY_UDP_DHALGO, "AES:128");
DistributionConfigImpl config = new DistributionConfigImpl(nonDefault);
RemoteTransportConfig transport = new RemoteTransportConfig(config, DistributionManager.NORMAL_DM_TYPE);
// start the first membership manager
try {
System.setProperty(GMSJoinLeave.BYPASS_DISCOVERY_PROPERTY, "true");
DistributedMembershipListener listener1 = mock(DistributedMembershipListener.class);
DMStats stats1 = mock(DMStats.class);
System.out.println("creating 1st membership manager");
m1 = MemberFactory.newMembershipManager(listener1, config, transport, stats1);
m1.startEventProcessing();
} finally {
System.getProperties().remove(GMSJoinLeave.BYPASS_DISCOVERY_PROPERTY);
}
// start the second membership manager
DistributedMembershipListener listener2 = mock(DistributedMembershipListener.class);
DMStats stats2 = mock(DMStats.class);
System.out.println("creating 2nd membership manager");
m2 = MemberFactory.newMembershipManager(listener2, config, transport, stats2);
m2.startEventProcessing();
// we have to check the views with JoinLeave because the membership
// manager queues new views for processing through the DM listener,
// which is a mock object in this test
System.out.println("waiting for views to stabilize");
JoinLeave jl1 = ((GMSMembershipManager) m1).getServices().getJoinLeave();
JoinLeave jl2 = ((GMSMembershipManager) m2).getServices().getJoinLeave();
long giveUp = System.currentTimeMillis() + 15000;
for (; ; ) {
try {
assertTrue("view = " + jl2.getView(), jl2.getView().size() == 2);
assertTrue("view = " + jl1.getView(), jl1.getView().size() == 2);
assertTrue(jl1.getView().getCreator().equals(jl2.getView().getCreator()));
assertTrue(jl1.getView().getViewId() == jl2.getView().getViewId());
break;
} catch (AssertionError e) {
if (System.currentTimeMillis() > giveUp) {
throw e;
}
}
}
System.out.println("testing multicast availability");
assertTrue(m1.testMulticast());
System.out.println("multicasting SerialAckedMessage from m1 to m2");
SerialAckedMessage msg = new SerialAckedMessage();
msg.setRecipient(m2.getLocalMember());
msg.setMulticast(true);
m1.send(new InternalDistributedMember[] { m2.getLocalMember() }, msg, null);
giveUp = System.currentTimeMillis() + 5000;
boolean verified = false;
Throwable problem = null;
while (giveUp > System.currentTimeMillis()) {
try {
verify(listener2).messageReceived(isA(SerialAckedMessage.class));
verified = true;
break;
} catch (Error e) {
problem = e;
Thread.sleep(500);
}
}
if (!verified) {
if (problem != null) {
problem.printStackTrace();
}
fail("Expected a multicast message to be received");
}
// let the managers idle for a while and get used to each other
Thread.sleep(4000l);
m2.shutdown();
assertTrue(!m2.isConnected());
assertTrue(m1.getView().size() == 1);
} finally {
if (m2 != null) {
m2.shutdown();
}
if (m1 != null) {
m1.shutdown();
}
if (l != null) {
l.stop();
}
}
}
use of org.apache.geode.distributed.internal.membership.gms.interfaces.JoinLeave in project geode by apache.
the class GMSHealthMonitorJUnitTest method initMocks.
@Before
public void initMocks() throws UnknownHostException {
// System.setProperty("gemfire.bind-address", "localhost");
mockDistConfig = mock(DistributionConfig.class);
mockConfig = mock(ServiceConfig.class);
messenger = mock(Messenger.class);
joinLeave = mock(JoinLeave.class);
manager = mock(Manager.class);
services = mock(Services.class);
Stopper stopper = mock(Stopper.class);
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]");
DM dm = mock(DM.class);
SocketCreatorFactory.setDistributionConfig(new DistributionConfigImpl(new Properties()));
InternalDistributedSystem system = InternalDistributedSystem.newInstanceForTesting(dm, nonDefault);
when(mockConfig.getDistributionConfig()).thenReturn(mockDistConfig);
when(mockConfig.getMemberTimeout()).thenReturn(memberTimeout);
when(mockConfig.getMembershipPortRange()).thenReturn(portRange);
when(services.getConfig()).thenReturn(mockConfig);
when(services.getMessenger()).thenReturn(messenger);
when(services.getJoinLeave()).thenReturn(joinLeave);
when(services.getCancelCriterion()).thenReturn(stopper);
when(services.getManager()).thenReturn(manager);
when(services.getStatistics()).thenReturn(new DistributionStats(system, statsId));
when(stopper.isCancelInProgress()).thenReturn(false);
if (mockMembers == null) {
mockMembers = new ArrayList<InternalDistributedMember>();
for (int i = 0; i < 7; i++) {
InternalDistributedMember mbr = new InternalDistributedMember("localhost", 8888 + i);
if (i == 0 || i == 1) {
mbr.setVmKind(DistributionManager.LOCATOR_DM_TYPE);
mbr.getNetMember().setPreferredForCoordinator(true);
}
mockMembers.add(mbr);
}
}
when(joinLeave.getMemberID()).thenReturn(mockMembers.get(myAddressIndex));
when(messenger.getMemberID()).thenReturn(mockMembers.get(myAddressIndex));
gmsHealthMonitor = new GMSHealthMonitorTest();
gmsHealthMonitor.init(services);
gmsHealthMonitor.start();
}
Aggregations