use of org.apache.geode.distributed.internal.membership.gms.Services 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.Services 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.Services 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.Services 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();
}
use of org.apache.geode.distributed.internal.membership.gms.Services in project geode by apache.
the class StatRecorderJUnitTest method setUp.
@Before
public void setUp() throws Exception {
stats = new MyStats();
// create a StatRecorder that has mock up/down protocols and stats
mockDownProtocol = mock(Protocol.class);
mockUpProtocol = mock(Protocol.class);
services = mock(Services.class);
when(services.getStatistics()).thenReturn(stats);
recorder = new StatRecorder();
recorder.setServices(services);
recorder.setUpProtocol(mockUpProtocol);
recorder.setDownProtocol(mockDownProtocol);
}
Aggregations