Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GEODE-9478: Fix status --dir to use file controller #6737

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
*/
package org.apache.geode.distributed;

import static java.lang.management.ManagementFactory.getRuntimeMXBean;
import static org.apache.geode.distributed.AbstractLauncher.Status.NOT_RESPONDING;
import static org.apache.geode.distributed.AbstractLauncher.Status.ONLINE;
import static org.apache.geode.distributed.AbstractLauncher.Status.STOPPED;
import static org.apache.geode.distributed.ConfigurationProperties.DISABLE_AUTO_RECONNECT;
Expand Down Expand Up @@ -217,6 +215,13 @@ public void statusWithPidReturnsOnlineWithDetails() throws Exception {
public void statusWithWorkingDirectoryReturnsOnlineWithDetails() throws Exception {
givenRunningLocator();

// Keep it as we are going to overwrite it
int pid = readPidFile();

// Sets a fake PID to ensure that the request is going through FileProcessController,
// because if not, the request would fail due to the PID not existing
givenPidFile(fakePid);

LocatorState locatorState = new Builder()
.setWorkingDirectory(getWorkingDirectoryPath())
.build()
Expand All @@ -230,62 +235,11 @@ public void statusWithWorkingDirectoryReturnsOnlineWithDetails() throws Exceptio
assertThat(locatorState.getJvmArguments()).isEqualTo(getJvmArguments());
assertThat(locatorState.getLogFile()).isEqualTo(getLogFilePath());
assertThat(locatorState.getMemberName()).isEqualTo(getUniqueName());
assertThat(locatorState.getPid().intValue()).isEqualTo(readPidFile());
assertThat(locatorState.getPid().intValue()).isEqualTo(pid);
assertThat(locatorState.getUptime()).isGreaterThan(0);
assertThat(locatorState.getWorkingDirectory()).isEqualTo(new File(".").getCanonicalPath());
}

@Test
public void statusWithEmptyPidFileThrowsIllegalArgumentException() {
givenEmptyPidFile();
LocatorLauncher launcher = new Builder()
.setWorkingDirectory(getWorkingDirectoryPath())
.build();

Throwable thrown = catchThrowable(launcher::status);

assertThat(thrown)
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("Invalid pid 'null' found in");
}

@Test
public void statusWithEmptyWorkingDirectoryReturnsNotRespondingWithDetails() throws Exception {
givenEmptyWorkingDirectory();

LocatorState locatorState = new Builder()
.setWorkingDirectory(getWorkingDirectoryPath())
.build()
.status();

assertThat(locatorState.getStatus()).isEqualTo(NOT_RESPONDING);
assertThat(locatorState.getClasspath()).isNull();
assertThat(locatorState.getGemFireVersion()).isEqualTo(GemFireVersion.getGemFireVersion());
assertThat(locatorState.getHost()).isEqualTo(getLocalHost().getCanonicalHostName());
assertThat(locatorState.getJavaVersion()).isEqualTo(System.getProperty("java.version"));
assertThat(locatorState.getJvmArguments()).isEqualTo(getRuntimeMXBean().getInputArguments());
assertThat(locatorState.getLogFile()).isNull();
assertThat(locatorState.getMemberName()).isNull();
assertThat(locatorState.getPid()).isNull();
assertThat(locatorState.getUptime().intValue()).isEqualTo(0);
assertThat(locatorState.getWorkingDirectory()).isEqualTo(getWorkingDirectoryPath());
}

/**
* This test takes > 1 minute to run in {@link LocatorLauncherLocalFileIntegrationTest}.
*/
@Test
public void statusWithStalePidFileReturnsNotResponding() {
givenPidFile(fakePid);

LocatorState locatorState = new Builder()
.setWorkingDirectory(getWorkingDirectoryPath())
.build()
.status();

assertThat(locatorState.getStatus()).isEqualTo(NOT_RESPONDING);
}

@Test
public void stopWithPidReturnsStopped() {
givenRunningLocator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@
*/
package org.apache.geode.distributed;

import static org.apache.geode.distributed.AbstractLauncher.Status.NOT_RESPONDING;
import static org.apache.geode.distributed.AbstractLauncher.Status.ONLINE;
import static org.apache.geode.distributed.AbstractLauncher.Status.STOPPED;
import static org.apache.geode.internal.inet.LocalHostUtil.getLocalHost;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowable;

import java.io.File;
import java.net.BindException;
Expand Down Expand Up @@ -149,6 +147,13 @@ public void statusWithPidReturnsOnlineWithDetails() throws Exception {
public void statusWithWorkingDirectoryReturnsOnlineWithDetails() throws Exception {
givenRunningLocator(withPort(0));

// Keep it as we are going to overwrite it
int pid = readPidFile();

// Sets a fake PID to ensure that the request is going through FileProcessController,
// because if not, the request would fail due to the PID not existing
givenPidFile(fakePid);

LocatorState locatorState = new Builder()
.setWorkingDirectory(getWorkingDirectoryPath())
.build()
Expand All @@ -161,62 +166,12 @@ public void statusWithWorkingDirectoryReturnsOnlineWithDetails() throws Exceptio
assertThat(locatorState.getJvmArguments()).isEqualTo(getJvmArguments());
assertThat(locatorState.getLogFile()).isEqualTo(getLogFile().getCanonicalPath());
assertThat(locatorState.getMemberName()).isEqualTo(getUniqueName());
assertThat(locatorState.getPid().intValue()).isEqualTo(readPidFile());
assertThat(locatorState.getPid().intValue()).isEqualTo(pid);
assertThat(locatorState.getStatus()).isEqualTo(ONLINE);
assertThat(locatorState.getUptime()).isGreaterThan(0);
assertThat(locatorState.getWorkingDirectory()).isEqualToIgnoringCase(getWorkingDirectoryPath());
}

@Test
public void statusWithEmptyPidFileThrowsIllegalArgumentException() {
givenEmptyPidFile();
LocatorLauncher launcher = new Builder()
.setWorkingDirectory(getWorkingDirectoryPath())
.build();

Throwable thrown = catchThrowable(launcher::status);

assertThat(thrown)
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("Invalid pid 'null' found in");
}

@Test
public void statusWithEmptyWorkingDirectoryReturnsNotRespondingWithDetails() throws Exception {
givenEmptyWorkingDirectory();

LocatorState locatorState = new Builder()
.setWorkingDirectory(getWorkingDirectoryPath())
.build()
.status();

assertThat(locatorState.getClasspath()).isNull();
assertThat(locatorState.getGemFireVersion()).isEqualTo(GemFireVersion.getGemFireVersion());
assertThat(locatorState.getHost()).isEqualTo(getLocalHost().getCanonicalHostName());
assertThat(locatorState.getJavaVersion()).isEqualTo(System.getProperty("java.version"));
assertThat(locatorState.getLogFile()).isNull();
assertThat(locatorState.getMemberName()).isNull();
assertThat(locatorState.getPid()).isNull();
assertThat(locatorState.getStatus()).isEqualTo(NOT_RESPONDING);
assertThat(locatorState.getUptime().intValue()).isEqualTo(0);
assertThat(locatorState.getWorkingDirectory()).isEqualTo(getWorkingDirectoryPath());
}

/**
* This test takes > 1 minute to run in {@link LocatorLauncherRemoteFileIntegrationTest}.
*/
@Test
public void statusWithStalePidFileReturnsNotResponding() {
givenPidFile(fakePid);

LocatorState locatorState = new Builder()
.setWorkingDirectory(getWorkingDirectoryPath())
.build()
.status();

assertThat(locatorState.getStatus()).isEqualTo(NOT_RESPONDING);
}

@Test
public void stopWithPidReturnsStopped() {
givenRunningLocator(withPort(0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
*/
package org.apache.geode.distributed;

import static org.apache.geode.distributed.AbstractLauncher.Status.NOT_RESPONDING;
import static org.apache.geode.distributed.AbstractLauncher.Status.ONLINE;
import static org.apache.geode.distributed.AbstractLauncher.Status.STOPPED;
import static org.apache.geode.distributed.ConfigurationProperties.DISABLE_AUTO_RECONNECT;
Expand Down Expand Up @@ -308,6 +307,13 @@ public void statusWithPidReturnsOnlineWithDetails() throws UnknownHostException
public void statusWithWorkingDirectoryReturnsOnlineWithDetails() throws UnknownHostException {
givenRunningServer();

// Keep it as we are going to overwrite it
int pid = readPidFile();

// Sets a fake PID to ensure that the request is going through FileProcessController,
// because if not, the request would fail due to the PID not existing
givenPidFile(fakePid);

ServerState serverState = new Builder()
.setWorkingDirectory(getWorkingDirectoryPath())
.build()
Expand All @@ -320,64 +326,12 @@ public void statusWithWorkingDirectoryReturnsOnlineWithDetails() throws UnknownH
assertThat(serverState.getJvmArguments()).isEqualTo(getJvmArguments());
assertThat(serverState.getLogFile()).isEqualTo(getLogFilePath());
assertThat(serverState.getMemberName()).isEqualTo(getUniqueName());
assertThat(serverState.getPid().intValue()).isEqualTo(readPidFile());
assertThat(serverState.getPid().intValue()).isEqualTo(pid);
assertThat(serverState.getStatus()).isEqualTo(ONLINE);
assertThat(serverState.getUptime()).isGreaterThan(0);
assertThat(serverState.getWorkingDirectory()).isEqualTo(getWorkingDirectoryPath());
}

@Test
public void statusWithEmptyPidFileThrowsIllegalArgumentException() {
givenEmptyPidFile();
ServerLauncher launcher = new Builder()
.setWorkingDirectory(getWorkingDirectoryPath())
.build();

Throwable thrown = catchThrowable(launcher::status);

assertThat(thrown)
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("Invalid pid 'null' found in");
}

@Test
public void statusWithEmptyWorkingDirectoryReturnsNotRespondingWithDetails()
throws UnknownHostException {
givenEmptyWorkingDirectory();

ServerState serverState = new Builder()
.setWorkingDirectory(getWorkingDirectoryPath())
.build()
.status();

assertThat(serverState.getClasspath()).isNull();
assertThat(serverState.getGemFireVersion()).isEqualTo(GemFireVersion.getGemFireVersion());
assertThat(serverState.getHost()).isEqualTo(getLocalHost().getCanonicalHostName());
assertThat(serverState.getJavaVersion()).isEqualTo(System.getProperty("java.version"));
assertThat(serverState.getJvmArguments()).isEqualTo(getJvmArguments());
assertThat(serverState.getLogFile()).isNull();
assertThat(serverState.getMemberName()).isNull();
assertThat(serverState.getPid()).isNull();
assertThat(serverState.getStatus()).isEqualTo(NOT_RESPONDING);
assertThat(serverState.getUptime().intValue()).isEqualTo(0);
assertThat(serverState.getWorkingDirectory()).isEqualTo(getWorkingDirectoryPath());
}

/**
* This test takes > 1 minute to run in {@link ServerLauncherLocalFileIntegrationTest}.
*/
@Test
public void statusWithStalePidFileReturnsNotResponding() {
givenPidFile(fakePid);

ServerState serverState = new Builder()
.setWorkingDirectory(getWorkingDirectoryPath())
.build()
.status();

assertThat(serverState.getStatus()).isEqualTo(NOT_RESPONDING);
}

@Test
public void stopWithPidReturnsStopped() {
givenRunningServer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@
*/
package org.apache.geode.distributed;

import static org.apache.geode.distributed.AbstractLauncher.Status.NOT_RESPONDING;
import static org.apache.geode.distributed.AbstractLauncher.Status.ONLINE;
import static org.apache.geode.distributed.AbstractLauncher.Status.STOPPED;
import static org.apache.geode.distributed.ConfigurationProperties.CACHE_XML_FILE;
import static org.apache.geode.internal.inet.LocalHostUtil.getLocalHost;
import static org.apache.geode.util.internal.GeodeGlossary.GEMFIRE_PREFIX;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowable;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -210,13 +208,20 @@ public void statusWithPidReturnsOnlineWithDetails() throws IOException {
public void statusWithWorkingDirectoryReturnsOnlineWithDetails() throws IOException {
givenRunningServer();

// Keep it as we are going to overwrite it
int pid = readPidFile();

// Sets a fake PID to ensure that the request is going through FileProcessController,
// because if not, the request would fail due to the PID not existing
givenPidFile(fakePid);

ServerState serverState = new Builder()
.setWorkingDirectory(getWorkingDirectoryPath())
.build()
.status();

assertThat(serverState.getStatus()).isEqualTo(ONLINE);
assertThat(serverState.getPid().intValue()).isEqualTo(readPidFile());
assertThat(serverState.getPid().intValue()).isEqualTo(pid);
assertThat(serverState.getUptime()).isGreaterThan(0);
assertThat(serverState.getWorkingDirectory()).isEqualTo(getWorkingDirectoryPath());
assertThat(serverState.getJvmArguments()).isEqualTo(getJvmArguments());
Expand All @@ -228,54 +233,6 @@ public void statusWithWorkingDirectoryReturnsOnlineWithDetails() throws IOExcept
assertThat(serverState.getMemberName()).isEqualTo(getUniqueName());
}

@Test
public void statusWithEmptyPidFileThrowsIllegalArgumentException() {
givenEmptyPidFile();

ServerLauncher launcher = new Builder()
.setWorkingDirectory(getWorkingDirectoryPath())
.build();

Throwable thrown = catchThrowable(launcher::status);

assertThat(thrown)
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("Invalid pid 'null' found in");
}

@Test
public void statusWithEmptyWorkingDirectoryReturnsNotRespondingWithDetails() throws IOException {
givenEmptyWorkingDirectory();

ServerState serverState = new Builder()
.setWorkingDirectory(getWorkingDirectoryPath())
.build()
.status();

assertThat(serverState.getStatus()).isEqualTo(NOT_RESPONDING);
assertThat(serverState.getPid()).isNull();
assertThat(serverState.getUptime().intValue()).isEqualTo(0);
assertThat(serverState.getWorkingDirectory()).isEqualTo(getWorkingDirectoryPath());
assertThat(serverState.getClasspath()).isNull();
assertThat(serverState.getGemFireVersion()).isEqualTo(GemFireVersion.getGemFireVersion());
assertThat(serverState.getJavaVersion()).isEqualTo(System.getProperty("java.version"));
assertThat(serverState.getLogFile()).isNull();
assertThat(serverState.getHost()).isEqualTo(getLocalHost().getCanonicalHostName());
assertThat(serverState.getMemberName()).isNull();
}

@Test
public void statusWithStalePidFileReturnsNotResponding() {
givenPidFile(fakePid);

ServerState serverState = new Builder()
.setWorkingDirectory(getWorkingDirectoryPath())
.build()
.status();

assertThat(serverState.getStatus()).isEqualTo(NOT_RESPONDING);
}

@Test
public void stopWithPidReturnsStopped() {
givenRunningServer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.io.File;
import java.io.FileNotFoundException;
Expand Down Expand Up @@ -83,6 +84,19 @@ public void createProcessController_returnsMBeanProcessController() throws Excep
assertThat(controller).isInstanceOf(MBeanOrFileProcessController.class);
}

@Test
public void createProcessController_returnsFileProcessController() throws Exception {
// arrange
when(parameters.getDirectory()).thenReturn(new File("./"));

// act
ProcessController controller =
factory.createProcessController(parameters);

// assert
assertThat(controller).isInstanceOf(FileProcessController.class);
}

@Test
public void createProcessController_withoutAttachAPI_returnsFileProcessController()
throws Exception {
Expand Down
Loading