use of org.apache.geode.distributed.ServerLauncher.Builder in project geode by apache.
the class ServerLauncherLocalIntegrationTest method testStartOverwritesStalePidFile.
@Test
public void testStartOverwritesStalePidFile() throws Throwable {
String rootFolder = this.temporaryFolder.getRoot().getCanonicalPath();
// create existing pid file
this.pidFile = new File(this.temporaryFolder.getRoot(), ProcessType.SERVER.getPidFileName());
assertFalse("Integer.MAX_VALUE shouldn't be the same as local pid " + Integer.MAX_VALUE, Integer.MAX_VALUE == ProcessUtils.identifyPid());
writePid(this.pidFile, Integer.MAX_VALUE);
// build and start the server
final Builder builder = new Builder().setDisableDefaultServer(true).setMemberName(getUniqueName()).setRedirectOutput(true).setWorkingDirectory(rootFolder).set(LOG_LEVEL, "config").set(MCAST_PORT, "0");
assertFalse(builder.getForce());
this.launcher = builder.build();
assertFalse(this.launcher.isForcing());
this.launcher.start();
try {
waitForServerToStart(this.launcher);
} catch (Throwable e) {
this.errorCollector.addError(e);
}
try {
// validate the pid file and its contents
assertTrue(this.pidFile.exists());
final int pid = readPid(this.pidFile);
assertTrue(pid > 0);
assertTrue(ProcessUtils.isProcessAlive(pid));
assertEquals(getPid(), pid);
} catch (Throwable e) {
this.errorCollector.addError(e);
}
try {
assertEquals(Status.STOPPED, this.launcher.stop().getStatus());
waitForFileToDelete(this.pidFile);
} catch (Throwable e) {
this.errorCollector.addError(e);
}
}
use of org.apache.geode.distributed.ServerLauncher.Builder in project geode by apache.
the class ServerLauncherTest method reconnectingDistributedSystemIsDisconnectedOnStop.
@Test
public void reconnectingDistributedSystemIsDisconnectedOnStop() throws Exception {
final Cache mockCache = mockContext.mock(Cache.class, "Cache");
final DistributedSystem mockDistributedSystem = mockContext.mock(DistributedSystem.class, "DistributedSystem");
final Cache mockReconnectedCache = mockContext.mock(Cache.class, "ReconnectedCache");
mockContext.checking(new Expectations() {
{
exactly(1).of(mockCache).isReconnecting();
will(returnValue(Boolean.TRUE));
exactly(1).of(mockCache).getReconnectedCache();
will(returnValue(mockReconnectedCache));
exactly(2).of(mockReconnectedCache).isReconnecting();
will(returnValue(Boolean.TRUE));
exactly(1).of(mockReconnectedCache).getReconnectedCache();
will(returnValue(null));
oneOf(mockReconnectedCache).getDistributedSystem();
will(returnValue(mockDistributedSystem));
oneOf(mockDistributedSystem).stopReconnecting();
oneOf(mockReconnectedCache).close();
}
});
final ServerLauncher serverLauncher = new Builder().setMemberName("serverOne").setCache(mockCache).build();
assertNotNull(serverLauncher);
serverLauncher.setIsRunningForTest();
serverLauncher.stop();
}
use of org.apache.geode.distributed.ServerLauncher.Builder in project geode by apache.
the class ServerLauncherTest method testIsServingWhenNoCacheServersExist.
@Test
public void testIsServingWhenNoCacheServersExist() {
final Cache mockCache = mockContext.mock(Cache.class, "Cache");
mockContext.checking(new Expectations() {
{
oneOf(mockCache).getCacheServers();
will(returnValue(Collections.emptyList()));
}
});
final ServerLauncher serverLauncher = new Builder().setMemberName("serverOne").build();
assertNotNull(serverLauncher);
assertEquals("serverOne", serverLauncher.getMemberName());
assertFalse(serverLauncher.isServing(mockCache));
}
use of org.apache.geode.distributed.ServerLauncher.Builder in project geode by apache.
the class ServerLauncherTest method testIsDefaultServerEnabledWhenNoCacheServersExistAndDefaultServerDisabled.
@Test
public void testIsDefaultServerEnabledWhenNoCacheServersExistAndDefaultServerDisabled() {
final Cache mockCache = mockContext.mock(Cache.class, "Cache");
mockContext.checking(new Expectations() {
{
oneOf(mockCache).getCacheServers();
will(returnValue(Collections.emptyList()));
}
});
final ServerLauncher serverLauncher = new Builder().setMemberName("serverOne").setDisableDefaultServer(true).build();
assertNotNull(serverLauncher);
assertEquals("serverOne", serverLauncher.getMemberName());
assertTrue(serverLauncher.isDisableDefaultServer());
assertFalse(serverLauncher.isDefaultServerEnabled(mockCache));
}
use of org.apache.geode.distributed.ServerLauncher.Builder in project geode by apache.
the class ServerLauncherTest method testSetAndGetPid.
@Test
public void testSetAndGetPid() {
Builder builder = new Builder();
assertNull(builder.getPid());
assertSame(builder, builder.setPid(0));
assertEquals(0, builder.getPid().intValue());
assertSame(builder, builder.setPid(1));
assertEquals(1, builder.getPid().intValue());
assertSame(builder, builder.setPid(1024));
assertEquals(1024, builder.getPid().intValue());
assertSame(builder, builder.setPid(12345));
assertEquals(12345, builder.getPid().intValue());
assertSame(builder, builder.setPid(null));
assertNull(builder.getPid());
}
Aggregations