Search in sources :

Example 31 with Builder

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));
}
Also used : Expectations(org.jmock.Expectations) Builder(org.apache.geode.distributed.ServerLauncher.Builder) Cache(org.apache.geode.cache.Cache) UnitTest(org.apache.geode.test.junit.categories.UnitTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 32 with Builder

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));
}
Also used : Expectations(org.jmock.Expectations) Builder(org.apache.geode.distributed.ServerLauncher.Builder) CacheServer(org.apache.geode.cache.server.CacheServer) Cache(org.apache.geode.cache.Cache) UnitTest(org.apache.geode.test.junit.categories.UnitTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 33 with Builder

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));
}
Also used : Expectations(org.jmock.Expectations) Builder(org.apache.geode.distributed.ServerLauncher.Builder) CacheServer(org.apache.geode.cache.server.CacheServer) Cache(org.apache.geode.cache.Cache) UnitTest(org.apache.geode.test.junit.categories.UnitTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 34 with Builder

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);
    }
}
Also used : Builder(org.apache.geode.distributed.ServerLauncher.Builder) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 35 with Builder

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);
    }
}
Also used : Builder(org.apache.geode.distributed.ServerLauncher.Builder) ServerState(org.apache.geode.distributed.ServerLauncher.ServerState) BindException(java.net.BindException) File(java.io.File) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

Builder (org.apache.geode.distributed.ServerLauncher.Builder)56 Test (org.junit.Test)56 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)31 UnitTest (org.apache.geode.test.junit.categories.UnitTest)29 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)27 File (java.io.File)18 Cache (org.apache.geode.cache.Cache)14 Expectations (org.jmock.Expectations)12 ServerState (org.apache.geode.distributed.ServerLauncher.ServerState)11 ArrayList (java.util.ArrayList)4 CacheServer (org.apache.geode.cache.server.CacheServer)4 InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)3 FileNotFoundException (java.io.FileNotFoundException)2 FileWriter (java.io.FileWriter)2 PrintWriter (java.io.PrintWriter)2 BindException (java.net.BindException)2 Properties (java.util.Properties)2 CacheCreation (org.apache.geode.internal.cache.xmlcache.CacheCreation)2 RegionAttributesCreation (org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation)2 ProcessStreamReader (org.apache.geode.internal.process.ProcessStreamReader)2