use of org.apache.geode.distributed.internal.membership.gms.mgr.GMSMembershipManager in project geode by apache.
the class DistributedSystemDUnitTest method testMembershipPortRangeWithExactThreeValues.
@Test
public void testMembershipPortRangeWithExactThreeValues() throws Exception {
Properties config = new Properties();
config.setProperty(LOCATORS, "localhost[" + getDUnitLocatorPort() + "]");
config.setProperty(MEMBERSHIP_PORT_RANGE, this.lowerBoundOfPortRange + "-" + this.upperBoundOfPortRange);
InternalDistributedSystem system = getSystem(config);
Cache cache = CacheFactory.create(system);
cache.addCacheServer();
DistributionManager dm = (DistributionManager) system.getDistributionManager();
InternalDistributedMember member = dm.getDistributionManagerId();
GMSMembershipManager gms = (GMSMembershipManager) MembershipManagerHelper.getMembershipManager(system);
JGroupsMessenger messenger = (JGroupsMessenger) gms.getServices().getMessenger();
String jgConfig = messenger.getJGroupsStackConfig();
assertThat(jgConfig).as("expected to find port_range=\"2\" in " + jgConfig).contains("port_range=\"2\"");
verifyMembershipPortsInRange(member, this.lowerBoundOfPortRange, this.upperBoundOfPortRange);
}
use of org.apache.geode.distributed.internal.membership.gms.mgr.GMSMembershipManager in project geode by apache.
the class ReconnectedCacheServerDUnitTest method testDefaultCacheServerNotCreatedOnReconnect.
@Test
public void testDefaultCacheServerNotCreatedOnReconnect() {
assertFalse(Boolean.getBoolean(DistributionConfig.GEMFIRE_PREFIX + "autoReconnect-useCacheXMLFile"));
GemFireCacheImpl gc = (GemFireCacheImpl) this.cache;
// fool the system into thinking cluster-config is being used
GMSMembershipManager mgr = (GMSMembershipManager) MembershipManagerHelper.getMembershipManager(gc.getDistributedSystem());
final boolean sharedConfigEnabled = true;
mgr.saveCacheXmlForReconnect(sharedConfigEnabled);
// the cache server config should now be stored in the cache's config
assertFalse(gc.getCacheServers().isEmpty());
int numServers = gc.getCacheServers().size();
assertNotNull(gc.getCacheConfig().getCacheServerCreation());
InternalDistributedSystem system = gc.getInternalDistributedSystem();
system.createAndStartCacheServers(gc.getCacheConfig().getCacheServerCreation(), gc);
assertEquals("found these cache servers:" + gc.getCacheServers(), numServers, gc.getCacheServers().size());
}
use of org.apache.geode.distributed.internal.membership.gms.mgr.GMSMembershipManager 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.mgr.GMSMembershipManager in project geode by apache.
the class GMSJoinLeaveTestHelper method getGmsJoinLeave.
private static GMSJoinLeave getGmsJoinLeave() {
InternalDistributedSystem distributedSystem = getInternalDistributedSystem();
DM dm = distributedSystem.getDM();
GMSMembershipManager membershipManager = (GMSMembershipManager) dm.getMembershipManager();
Services services = membershipManager.getServices();
return (GMSJoinLeave) services.getJoinLeave();
}
use of org.apache.geode.distributed.internal.membership.gms.mgr.GMSMembershipManager in project geode by apache.
the class DistributedSystemDUnitTest method testSpecificTcpPort.
/**
* test the ability to set the port used to listen for tcp/ip connections
*/
@Test
public void testSpecificTcpPort() throws Exception {
Properties config = new Properties();
config.put(LOCATORS, "localhost[" + getDUnitLocatorPort() + "]");
config.setProperty(TCP_PORT, String.valueOf(this.tcpPort));
InternalDistributedSystem system = getSystem(config);
DistributionManager dm = (DistributionManager) system.getDistributionManager();
GMSMembershipManager mgr = (GMSMembershipManager) dm.getMembershipManager();
assertThat(mgr.getDirectChannelPort()).isEqualTo(this.tcpPort);
}
Aggregations