use of org.apache.geode.distributed.internal.membership.gms.interfaces.Manager in project geode by apache.
the class StatRecorderJUnitTest method recorderHandlesRejectedExecution.
@Test
public void recorderHandlesRejectedExecution() throws Exception {
Message msg = mock(Message.class);
when(msg.getHeader(any(Short.class))).thenReturn(Header.createDataHeader(1L, (short) 1, true));
when(msg.size()).thenReturn(150L);
// GEODE-1178, the TP protocol may throw a RejectedExecutionException & StatRecorder should
// retry
when(mockDownProtocol.down(any(Event.class))).thenThrow(new RejectedExecutionException());
// after the first down() throws an exception we want StatRecorder to retry, so
// we set the Manager to say no shutdown is in progress the first time and then say
// one IS in progress so we can break out of the StatRecorder exception handling loop
when(services.getCancelCriterion()).thenReturn(new Services().getCancelCriterion());
Manager manager = mock(Manager.class);
when(services.getManager()).thenReturn(manager);
when(manager.shutdownInProgress()).thenReturn(Boolean.FALSE, Boolean.TRUE);
verify(mockDownProtocol, never()).down(isA(Event.class));
Event evt = new Event(Event.MSG, msg);
recorder.down(evt);
verify(mockDownProtocol, times(2)).down(isA(Event.class));
}
use of org.apache.geode.distributed.internal.membership.gms.interfaces.Manager in project geode by apache.
the class GMSJoinLeaveJUnitTest method initMocks.
public void initMocks(boolean enableNetworkPartition, boolean useTestGMSJoinLeave) throws UnknownHostException {
mockDistConfig = mock(DistributionConfig.class);
when(mockDistConfig.getEnableNetworkPartitionDetection()).thenReturn(enableNetworkPartition);
when(mockDistConfig.getLocators()).thenReturn("localhost[8888]");
when(mockDistConfig.getSecurityUDPDHAlgo()).thenReturn("");
mockConfig = mock(ServiceConfig.class);
when(mockDistConfig.getStartLocator()).thenReturn("localhost[12345]");
when(mockConfig.getDistributionConfig()).thenReturn(mockDistConfig);
when(mockDistConfig.getLocators()).thenReturn("localhost[12345]");
when(mockDistConfig.getMcastPort()).thenReturn(0);
when(mockDistConfig.getMemberTimeout()).thenReturn(2000);
authenticator = mock(Authenticator.class);
gmsJoinLeaveMemberId = new InternalDistributedMember("localhost", 8887);
messenger = mock(Messenger.class);
when(messenger.getMemberID()).thenReturn(gmsJoinLeaveMemberId);
stopper = mock(Stopper.class);
when(stopper.isCancelInProgress()).thenReturn(false);
manager = mock(Manager.class);
healthMonitor = mock(HealthMonitor.class);
when(healthMonitor.getFailureDetectionPort()).thenReturn(Integer.valueOf(-1));
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.getManager()).thenReturn(manager);
when(services.getHealthMonitor()).thenReturn(healthMonitor);
Timer t = new Timer(true);
when(services.getTimer()).thenReturn(t);
mockMembers = new InternalDistributedMember[4];
for (int i = 0; i < mockMembers.length; i++) {
mockMembers[i] = new InternalDistributedMember("localhost", 8888 + i);
}
mockOldMember = new InternalDistributedMember("localhost", 8700, Version.GFE_56);
if (useTestGMSJoinLeave) {
gmsJoinLeave = new GMSJoinLeaveTest();
} else {
gmsJoinLeave = new GMSJoinLeave();
}
gmsJoinLeave.init(services);
gmsJoinLeave.start();
gmsJoinLeave.started();
}
use of org.apache.geode.distributed.internal.membership.gms.interfaces.Manager in project geode by apache.
the class GMSJoinLeaveJUnitTest method testForceDisconnectedFromNewView.
@Test
public void testForceDisconnectedFromNewView() throws IOException {
// enabledNetworkPartition;
initMocks(true);
Manager mockManager = mock(Manager.class);
when(services.getManager()).thenReturn(mockManager);
prepareAndInstallView(mockMembers[0], createMemberList(mockMembers[0], gmsJoinLeaveMemberId));
int viewId = 2;
List<InternalDistributedMember> mbrs = new LinkedList<>();
mbrs.add(mockMembers[1]);
mbrs.add(mockMembers[2]);
mbrs.add(mockMembers[3]);
// install the view
NetView netView = new NetView(mockMembers[0], viewId, mbrs);
InstallViewMessage installViewMessage = getInstallViewMessage(netView, credentials, false);
gmsJoinLeave.processMessage(installViewMessage);
Assert.assertNotEquals(netView, gmsJoinLeave.getView());
verify(mockManager).forceDisconnect(isA(String.class));
}
use of org.apache.geode.distributed.internal.membership.gms.interfaces.Manager 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.Manager in project geode by apache.
the class DistributionManagerDUnitTest method testWaitForViewInstallation.
/**
* install a new view and show that waitForViewInstallation works as expected
*/
@Test
public void testWaitForViewInstallation() {
getSystem(new Properties());
MembershipManager mgr = basicGetSystem().getDM().getMembershipManager();
final NetView v = mgr.getView();
final boolean[] passed = new boolean[1];
Thread t = new Thread("wait for view installation") {
public void run() {
try {
((DistributionManager) basicGetSystem().getDM()).waitForViewInstallation(v.getViewId() + 1);
synchronized (passed) {
passed[0] = true;
}
} catch (InterruptedException e) {
// failed
}
}
};
t.setDaemon(true);
t.start();
Wait.pause(2000);
NetView newView = new NetView(v, v.getViewId() + 1);
((Manager) mgr).installView(newView);
Wait.pause(2000);
synchronized (passed) {
Assert.assertTrue(passed[0]);
}
}
Aggregations