Search in sources :

Example 41 with Builder

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

Example 42 with Builder

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();
}
Also used : Expectations(org.jmock.Expectations) Builder(org.apache.geode.distributed.ServerLauncher.Builder) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) 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 43 with Builder

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));
}
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 44 with Builder

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));
}
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 45 with Builder

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

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