use of org.apache.geode.distributed.ServerLauncher.Builder in project geode by apache.
the class ServerLauncherTest method testIsDefaultServerEnabled.
@Test
public void testIsDefaultServerEnabled() {
final Cache mockCache = mockContext.mock(Cache.class, "Cache");
mockContext.checking(new Expectations() {
{
oneOf(mockCache).getCacheServers();
will(returnValue(Collections.emptyList()));
}
});
ServerLauncher serverLauncher = new Builder().setMemberName("serverOne").build();
assertNotNull(serverLauncher);
assertEquals("serverOne", serverLauncher.getMemberName());
assertFalse(serverLauncher.isDisableDefaultServer());
assertTrue(serverLauncher.isDefaultServerEnabled(mockCache));
}
use of org.apache.geode.distributed.ServerLauncher.Builder in project geode by apache.
the class ServerLauncherTest method testIsDefaultServerEnabledWhenCacheServersExist.
@Test
public void testIsDefaultServerEnabledWhenCacheServersExist() {
final Cache mockCache = mockContext.mock(Cache.class, "Cache");
final CacheServer mockCacheServer = mockContext.mock(CacheServer.class, "CacheServer");
mockContext.checking(new Expectations() {
{
oneOf(mockCache).getCacheServers();
will(returnValue(Collections.singletonList(mockCacheServer)));
}
});
final ServerLauncher serverLauncher = new Builder().setMemberName("serverOne").setDisableDefaultServer(false).build();
assertNotNull(serverLauncher);
assertEquals("serverOne", serverLauncher.getMemberName());
assertFalse(serverLauncher.isDisableDefaultServer());
assertFalse(serverLauncher.isDefaultServerEnabled(mockCache));
}
use of org.apache.geode.distributed.ServerLauncher.Builder in project geode by apache.
the class ServerLauncherTest method testIsServing.
@Test
public void testIsServing() {
final Cache mockCache = mockContext.mock(Cache.class, "Cache");
final CacheServer mockCacheServer = mockContext.mock(CacheServer.class, "CacheServer");
mockContext.checking(new Expectations() {
{
oneOf(mockCache).getCacheServers();
will(returnValue(Collections.singletonList(mockCacheServer)));
}
});
final ServerLauncher serverLauncher = new Builder().setMemberName("serverOne").build();
assertNotNull(serverLauncher);
assertEquals("serverOne", serverLauncher.getMemberName());
assertTrue(serverLauncher.isServing(mockCache));
}
use of org.apache.geode.distributed.ServerLauncher.Builder in project geode by apache.
the class ServerLauncherWithProviderIntegrationTest method testBootstrapGemFireServerWithProvider.
// NOTE make sure bugs like Trac #51201 never happen again!!!
@Test
public void testBootstrapGemFireServerWithProvider() throws Throwable {
Cache mockCache = Mockito.mock(Cache.class);
MockServerLauncherCacheProvider.setCache(mockCache);
this.launcher = new Builder().setDisableDefaultServer(true).setForce(true).setMemberName(getUniqueName()).setSpringXmlLocation("spring/spring-gemfire-context.xml").set(MCAST_PORT, "0").build();
assertNotNull(this.launcher);
try {
assertEquals(Status.ONLINE, this.launcher.start().getStatus());
waitForServerToStart(this.launcher);
Cache cache = this.launcher.getCache();
assertEquals(mockCache, cache);
} catch (Throwable e) {
this.errorCollector.addError(e);
}
try {
assertEquals(Status.STOPPED, this.launcher.stop().getStatus());
assertNull(this.launcher.getCache());
} catch (Throwable e) {
this.errorCollector.addError(e);
}
}
use of org.apache.geode.distributed.ServerLauncher.Builder in project geode by apache.
the class ServerLauncherLocalIntegrationTest method testStartWithDefaultPortInUseFails.
@Test
public void testStartWithDefaultPortInUseFails() throws Throwable {
String rootFolder = this.temporaryFolder.getRoot().getCanonicalPath();
// generate one free port and then use TEST_OVERRIDE_DEFAULT_PORT_PROPERTY
this.socket = SocketCreatorFactory.getSocketCreatorForComponent(SecurableCommunicationChannel.CLUSTER).createServerSocket(this.serverPort, 50, null, -1);
assertFalse(AvailablePort.isPortAvailable(this.serverPort, AvailablePort.SOCKET));
// build and start the server
final Builder builder = new Builder().setMemberName(getUniqueName()).setRedirectOutput(true).setWorkingDirectory(rootFolder).set(LOG_LEVEL, "config").set(MCAST_PORT, "0");
this.launcher = builder.build();
RuntimeException expected = null;
try {
this.launcher.start();
// why did it not fail like it's supposed to?
final String property = System.getProperty(AbstractCacheServer.TEST_OVERRIDE_DEFAULT_PORT_PROPERTY);
assertNotNull(property);
assertEquals(this.serverPort, Integer.valueOf(property).intValue());
assertFalse(AvailablePort.isPortAvailable(this.serverPort, AvailablePort.SOCKET));
fail("Server port is " + this.launcher.getCache().getCacheServers().get(0).getPort());
fail("ServerLauncher start should have thrown RuntimeException caused by BindException");
} catch (RuntimeException e) {
expected = e;
assertNotNull(expected.getMessage());
// BindException text varies by platform
} catch (Throwable e) {
this.errorCollector.addError(e);
}
try {
assertNotNull(expected);
final Throwable cause = expected.getCause();
assertNotNull(cause);
assertTrue(cause instanceof BindException);
// BindException string varies by platform
} catch (Throwable e) {
this.errorCollector.addError(e);
}
try {
this.pidFile = new File(this.temporaryFolder.getRoot(), ProcessType.SERVER.getPidFileName());
assertFalse("Pid file should not exist: " + this.pidFile, this.pidFile.exists());
// creation of log file seems to be random -- look into why sometime
final String logFileName = getUniqueName() + ".log";
assertFalse("Log file should not exist: " + logFileName, new File(this.temporaryFolder.getRoot(), logFileName).exists());
} catch (Throwable e) {
this.errorCollector.addError(e);
}
// just in case the launcher started...
ServerState status = null;
try {
status = this.launcher.stop();
} catch (Throwable t) {
// ignore
}
try {
waitForFileToDelete(this.pidFile);
assertEquals(getExpectedStopStatusForNotRunning(), status.getStatus());
} catch (Throwable e) {
this.errorCollector.addError(e);
}
}
Aggregations