use of org.apache.geode.distributed.internal.membership.gms.ServiceConfig 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.ServiceConfig in project geode by apache.
the class StatRecorderJUnitTest method messengerStackHoldsStatRecorder.
/**
* Ensure that the messenger JGroups configuration XML strings contain the statistics recorder
* protocol
*/
@Test
public void messengerStackHoldsStatRecorder() throws Exception {
Services mockServices = mock(Services.class);
ServiceConfig mockConfig = mock(ServiceConfig.class);
when(mockServices.getConfig()).thenReturn(mockConfig);
// first test to see if the non-multicast stack has the recorder installed
Properties nonDefault = new Properties();
nonDefault.put(MCAST_PORT, "0");
nonDefault.put(LOCATORS, "localhost[12345]");
DistributionConfigImpl config = new DistributionConfigImpl(nonDefault);
when(mockConfig.getDistributionConfig()).thenReturn(config);
RemoteTransportConfig transport = new RemoteTransportConfig(config, DistributionManager.NORMAL_DM_TYPE);
when(mockConfig.getTransport()).thenReturn(transport);
JGroupsMessenger messenger = new JGroupsMessenger();
messenger.init(mockServices);
String jgroupsConfig = messenger.getJGroupsStackConfig();
System.out.println(jgroupsConfig);
assertTrue(jgroupsConfig.contains("gms.messenger.StatRecorder"));
// now test to see if the multicast stack has the recorder installed
nonDefault.put(MCAST_PORT, "12345");
config = new DistributionConfigImpl(nonDefault);
transport = new RemoteTransportConfig(config, DistributionManager.NORMAL_DM_TYPE);
when(mockConfig.getDistributionConfig()).thenReturn(config);
when(mockConfig.getTransport()).thenReturn(transport);
messenger = new JGroupsMessenger();
messenger.init(mockServices);
assertTrue(jgroupsConfig.contains("gms.messenger.StatRecorder"));
}
use of org.apache.geode.distributed.internal.membership.gms.ServiceConfig in project geode by apache.
the class GMSEncryptJUnitTest method initMocks.
private void initMocks(String algo) throws Exception {
Properties nonDefault = new Properties();
nonDefault.put(ConfigurationProperties.SECURITY_UDP_DHALGO, algo);
DistributionConfigImpl config = new DistributionConfigImpl(nonDefault);
RemoteTransportConfig tconfig = new RemoteTransportConfig(config, DistributionManager.NORMAL_DM_TYPE);
ServiceConfig serviceConfig = new ServiceConfig(tconfig, config);
services = mock(Services.class);
when(services.getConfig()).thenReturn(serviceConfig);
mockMembers = new InternalDistributedMember[4];
for (int i = 0; i < mockMembers.length; i++) {
mockMembers[i] = new InternalDistributedMember("localhost", 8888 + i);
}
int viewId = 1;
List<InternalDistributedMember> mbrs = new LinkedList<>();
mbrs.add(mockMembers[0]);
mbrs.add(mockMembers[1]);
mbrs.add(mockMembers[2]);
// prepare the view
netView = new NetView(mockMembers[0], viewId, mbrs);
}
use of org.apache.geode.distributed.internal.membership.gms.ServiceConfig in project geode by apache.
the class MembershipJUnitTest method testMulticastDiscoveryNotAllowed.
@Test
public void testMulticastDiscoveryNotAllowed() {
Properties nonDefault = new Properties();
nonDefault.put(DISABLE_TCP, "true");
nonDefault.put(MCAST_PORT, "12345");
nonDefault.put(LOG_FILE, "");
nonDefault.put(LOG_LEVEL, "fine");
nonDefault.put(LOCATORS, "");
DistributionConfigImpl config = new DistributionConfigImpl(nonDefault);
RemoteTransportConfig transport = new RemoteTransportConfig(config, DistributionManager.NORMAL_DM_TYPE);
ServiceConfig serviceConfig = mock(ServiceConfig.class);
when(serviceConfig.getDistributionConfig()).thenReturn(config);
when(serviceConfig.getTransport()).thenReturn(transport);
Services services = mock(Services.class);
when(services.getConfig()).thenReturn(serviceConfig);
GMSJoinLeave joinLeave = new GMSJoinLeave();
try {
joinLeave.init(services);
throw new Error("expected a GemFireConfigException to be thrown because no locators are configured");
} catch (GemFireConfigException e) {
// expected
}
}
use of org.apache.geode.distributed.internal.membership.gms.ServiceConfig in project geode by apache.
the class MembershipJUnitTest method testJoinTimeoutSetting.
@Test
public void testJoinTimeoutSetting() throws Exception {
long timeout = 30000;
Properties nonDefault = new Properties();
nonDefault.put(MEMBER_TIMEOUT, "" + timeout);
DistributionConfigImpl config = new DistributionConfigImpl(nonDefault);
RemoteTransportConfig transport = new RemoteTransportConfig(config, DistributionManager.NORMAL_DM_TYPE);
ServiceConfig sc = new ServiceConfig(transport, config);
assertEquals(2 * timeout + ServiceConfig.MEMBER_REQUEST_COLLECTION_INTERVAL, sc.getJoinTimeout());
nonDefault.clear();
config = new DistributionConfigImpl(nonDefault);
transport = new RemoteTransportConfig(config, DistributionManager.NORMAL_DM_TYPE);
sc = new ServiceConfig(transport, config);
assertEquals(24000, sc.getJoinTimeout());
nonDefault.clear();
nonDefault.put(LOCATORS, SocketCreator.getLocalHost().getHostAddress() + "[" + 12345 + "]");
config = new DistributionConfigImpl(nonDefault);
transport = new RemoteTransportConfig(config, DistributionManager.NORMAL_DM_TYPE);
sc = new ServiceConfig(transport, config);
assertEquals(60000, sc.getJoinTimeout());
timeout = 2000;
System.setProperty("p2p.joinTimeout", "" + timeout);
try {
config = new DistributionConfigImpl(nonDefault);
transport = new RemoteTransportConfig(config, DistributionManager.NORMAL_DM_TYPE);
sc = new ServiceConfig(transport, config);
assertEquals(timeout, sc.getJoinTimeout());
} finally {
System.getProperties().remove("p2p.joinTimeout");
}
}
Aggregations