use of org.apache.geode.distributed.internal.InternalLocator in project geode by apache.
the class LocatorLauncherTest method shouldBeMockable.
@Test
public void shouldBeMockable() throws Exception {
LocatorLauncher mockLocatorLauncher = mock(LocatorLauncher.class);
InternalLocator mockInternalLocator = mock(InternalLocator.class);
when(mockLocatorLauncher.getLocator()).thenReturn(mockInternalLocator);
when(mockLocatorLauncher.getId()).thenReturn("ID");
assertThat(mockLocatorLauncher.getLocator()).isSameAs(mockInternalLocator);
assertThat(mockLocatorLauncher.getId()).isEqualTo("ID");
}
use of org.apache.geode.distributed.internal.InternalLocator in project geode by apache.
the class GMSMembershipManager method forceDisconnect.
@Override
public void forceDisconnect(final String reason) {
if (GMSMembershipManager.this.shutdownInProgress || isJoining()) {
// probably a race condition
return;
}
setShutdown();
final Exception shutdownCause = new ForcedDisconnectException(reason);
// cache the exception so it can be appended to ShutdownExceptions
services.setShutdownCause(shutdownCause);
services.getCancelCriterion().cancel(reason);
AlertAppender.getInstance().shuttingDown();
if (!inhibitForceDisconnectLogging) {
logger.fatal(LocalizedMessage.create(LocalizedStrings.GroupMembershipService_MEMBERSHIP_SERVICE_FAILURE_0, reason), shutdownCause);
}
if (!services.getConfig().getDistributionConfig().getDisableAutoReconnect()) {
saveCacheXmlForReconnect();
}
Thread reconnectThread = new Thread(() -> {
// stop server locators immediately since they may not have correct
// information. This has caused client failures in bridge/wan
// network-down testing
InternalLocator loc = (InternalLocator) Locator.getLocator();
if (loc != null) {
loc.stop(true, !services.getConfig().getDistributionConfig().getDisableAutoReconnect(), false);
}
uncleanShutdown(reason, shutdownCause);
});
reconnectThread.setName("DisconnectThread");
reconnectThread.setDaemon(false);
reconnectThread.start();
}
use of org.apache.geode.distributed.internal.InternalLocator in project geode by apache.
the class UploadJarFunction method execute.
@Override
public void execute(FunctionContext context) {
InternalLocator locator = (InternalLocator) Locator.getLocator();
Object[] args = (Object[]) context.getArguments();
String group = (String) args[0];
String jarName = (String) args[1];
if (locator != null && group != null && jarName != null) {
ClusterConfigurationService sharedConfig = locator.getSharedConfiguration();
if (sharedConfig != null) {
try {
byte[] jarBytes = sharedConfig.getJarBytesFromThisLocator(group, jarName);
context.getResultSender().lastResult(jarBytes);
} catch (Exception e) {
logger.error(e);
context.getResultSender().sendException(e);
}
}
}
// TODO: Why does this not throw an IllegalStateException?
context.getResultSender().lastResult(null);
}
use of org.apache.geode.distributed.internal.InternalLocator in project geode by apache.
the class ReconnectDUnitTest method testReconnectALocator.
@Test
public void testReconnectALocator() throws Exception {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
VM locatorVm = host.getVM(3);
DistributedMember dm, newdm;
final int locPort = locatorPort;
final int secondLocPort = AvailablePortHelper.getRandomAvailableTCPPort();
DistributedTestUtils.deleteLocatorStateFile(locPort, secondLocPort);
final String xmlFileLoc = (new File(".")).getAbsolutePath();
// This locator was started in setUp.
File locatorViewLog = new File(locatorVm.getWorkingDirectory(), "locator" + locatorPort + "views.log");
assertTrue("Expected to find " + locatorViewLog.getPath() + " file", locatorViewLog.exists());
long logSize = locatorViewLog.length();
vm0.invoke("Create a second locator", () -> {
locatorPort = locPort;
Properties props = getDistributedSystemProperties();
props.put(MAX_WAIT_TIME_RECONNECT, "1000");
props.put(MAX_NUM_RECONNECT_TRIES, "2");
props.put(LOCATORS, props.get(LOCATORS) + ",localhost[" + locPort + "]");
props.put(ENABLE_CLUSTER_CONFIGURATION, "false");
try {
Locator.startLocatorAndDS(secondLocPort, null, props);
} catch (IOException e) {
Assert.fail("exception starting locator", e);
}
});
File locator2ViewLog = new File(vm0.getWorkingDirectory(), "locator" + secondLocPort + "views.log");
assertTrue("Expected to find " + locator2ViewLog.getPath() + " file", locator2ViewLog.exists());
long log2Size = locator2ViewLog.length();
// create a cache in vm1 so there is more weight in the system
vm1.invoke("Create Cache and Regions from cache.xml", () -> {
locatorPort = locPort;
Properties props = getDistributedSystemProperties();
props.put(CACHE_XML_FILE, xmlFileLoc + fileSeparator + "MyDisconnect-cache.xml");
props.put(MAX_WAIT_TIME_RECONNECT, "1000");
props.put(MAX_NUM_RECONNECT_TRIES, "2");
ReconnectDUnitTest.savedSystem = getSystem(props);
Cache cache = getCache();
Region myRegion = cache.getRegion("root/myRegion");
myRegion.put("MyKey1", "MyValue1");
return savedSystem.getDistributedMember();
});
try {
dm = getDMID(vm0);
createGfshWaitingThread(vm0);
forceDisconnect(vm0);
newdm = waitForReconnect(vm0);
assertGfshWaitingThreadAlive(vm0);
assertTrue("Expected the restarted member to be hosting a running locator", vm0.invoke("check for running locator", () -> {
Awaitility.await("waiting for locator to restart").atMost(30, TimeUnit.SECONDS).until(Locator::getLocator, notNullValue());
if (((InternalLocator) Locator.getLocator()).isStopped()) {
LogWriterUtils.getLogWriter().error("found a stopped locator");
return false;
}
return true;
}));
assertNotSame("expected a reconnect to occur in the locator", dm, newdm);
// the log should have been opened and appended with a new view
assertTrue("expected " + locator2ViewLog.getPath() + " to grow in size", locator2ViewLog.length() > log2Size);
// the other locator should have logged a new view
assertTrue("expected " + locatorViewLog.getPath() + " to grow in size", locatorViewLog.length() > logSize);
} finally {
vm0.invoke(new SerializableRunnable("stop locator") {
public void run() {
Locator loc = Locator.getLocator();
if (loc != null) {
loc.stop();
}
if (gfshThread != null && gfshThread.isAlive()) {
gfshThread.interrupt();
}
gfshThread = null;
}
});
DistributedTestUtils.deleteLocatorStateFile(locPort);
DistributedTestUtils.deleteLocatorStateFile(secondLocPort);
}
}
use of org.apache.geode.distributed.internal.InternalLocator in project geode by apache.
the class FetchSharedConfigurationStatusFunction method execute.
@Override
public void execute(FunctionContext context) {
InternalLocator locator = InternalLocator.getLocator();
InternalCache cache = GemFireCacheImpl.getInstance();
DistributedMember member = cache.getDistributedSystem().getDistributedMember();
SharedConfigurationStatus status = locator.getSharedConfigurationStatus().getStatus();
String memberId = member.getName();
if (StringUtils.isBlank(memberId)) {
memberId = member.getId();
}
CliFunctionResult result = new CliFunctionResult(memberId, new String[] { status.name() });
context.getResultSender().lastResult(result);
}
Aggregations