DATAGEODE-180 - Add null, no-op Appender to JUL, Log4j and Logback logging configuration.
Speed up GemFireDataSourceUsingNonSpringConifguredGemFireServerIntegationTests. Refactor test framework supporting classes.
This commit is contained in:
@@ -93,26 +93,29 @@ public class GemFireDataSourceUsingNonSpringConfiguredGemFireServerIntegrationTe
|
|||||||
|
|
||||||
File serverWorkingDirectory = new File(FileSystemUtils.WORKING_DIRECTORY, serverName.toLowerCase());
|
File serverWorkingDirectory = new File(FileSystemUtils.WORKING_DIRECTORY, serverName.toLowerCase());
|
||||||
|
|
||||||
Assert.isTrue(serverWorkingDirectory.isDirectory() || serverWorkingDirectory.mkdirs());
|
Assert.isTrue(serverWorkingDirectory.isDirectory() || serverWorkingDirectory.mkdirs(),
|
||||||
|
String.format("Server working directory [%s] does not exist and could not be created", serverWorkingDirectory));
|
||||||
|
|
||||||
writeAsCacheXmlFileToDirectory("gemfire-datasource-integration-test-cache.xml", serverWorkingDirectory);
|
writeAsCacheXmlFileToDirectory("gemfire-datasource-integration-test-cache.xml", serverWorkingDirectory);
|
||||||
|
|
||||||
Assert.isTrue(new File(serverWorkingDirectory, "cache.xml").isFile(), String.format(
|
Assert.isTrue(new File(serverWorkingDirectory, "cache.xml").isFile(),
|
||||||
"Expected a cache.xml file to exist in directory (%1$s)!", serverWorkingDirectory));
|
String.format("Expected a cache.xml file to exist in directory [%s]", serverWorkingDirectory));
|
||||||
|
|
||||||
List<String> arguments = new ArrayList<>(5);
|
List<String> arguments = new ArrayList<>(5);
|
||||||
|
|
||||||
arguments.add(ServerLauncher.Command.START.getName());
|
arguments.add(ServerLauncher.Command.START.getName());
|
||||||
arguments.add(String.format("-Dgemfire.name=%1$s", serverName));
|
arguments.add(String.format("-Dgemfire.name=%s", serverName));
|
||||||
arguments.add(String.format("-Dgemfire.log-level=%1$s", "error"));
|
arguments.add(String.format("-Dgemfire.log-level=%s", GEMFIRE_LOG_LEVEL));
|
||||||
|
|
||||||
gemfireServer = ProcessExecutor.launch(serverWorkingDirectory, customClasspath(), ServerLauncher.class,
|
gemfireServer = ProcessExecutor.launch(serverWorkingDirectory, customClasspath(),
|
||||||
arguments.toArray(new String[arguments.size()]));
|
GemFireBasedServerProcess.class, arguments.toArray(new String[0]));
|
||||||
|
|
||||||
waitForProcessStart(TimeUnit.SECONDS.toMillis(20), gemfireServer, GemFireBasedServerProcess.getServerProcessControlFilename());
|
waitForProcessStart(TimeUnit.SECONDS.toMillis(20), gemfireServer,
|
||||||
|
GemFireBasedServerProcess.getServerProcessControlFilename());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void writeAsCacheXmlFileToDirectory(String classpathResource, File serverWorkingDirectory) throws IOException {
|
private static void writeAsCacheXmlFileToDirectory(String classpathResource, File serverWorkingDirectory) throws IOException {
|
||||||
|
|
||||||
FileCopyUtils.copy(new ClassPathResource(classpathResource).getInputStream(),
|
FileCopyUtils.copy(new ClassPathResource(classpathResource).getInputStream(),
|
||||||
new FileOutputStream(new File(serverWorkingDirectory, "cache.xml")));
|
new FileOutputStream(new File(serverWorkingDirectory, "cache.xml")));
|
||||||
}
|
}
|
||||||
@@ -121,7 +124,7 @@ public class GemFireDataSourceUsingNonSpringConfiguredGemFireServerIntegrationTe
|
|||||||
|
|
||||||
String[] classpathElements = ProcessExecutor.JAVA_CLASSPATH.split(File.pathSeparator);
|
String[] classpathElements = ProcessExecutor.JAVA_CLASSPATH.split(File.pathSeparator);
|
||||||
|
|
||||||
List<String> customClasspath = new ArrayList<String>(classpathElements.length);
|
List<String> customClasspath = new ArrayList<>(classpathElements.length);
|
||||||
|
|
||||||
for (String classpathElement : classpathElements) {
|
for (String classpathElement : classpathElements) {
|
||||||
if (!classpathElement.contains("spring-data-gemfire")) {
|
if (!classpathElement.contains("spring-data-gemfire")) {
|
||||||
@@ -132,12 +135,14 @@ public class GemFireDataSourceUsingNonSpringConfiguredGemFireServerIntegrationTe
|
|||||||
return StringUtils.collectionToDelimitedString(customClasspath, File.pathSeparator);
|
return StringUtils.collectionToDelimitedString(customClasspath, File.pathSeparator);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void waitForProcessStart(final long milliseconds, final ProcessWrapper process, final String processControlFilename) {
|
private static void waitForProcessStart(long milliseconds, ProcessWrapper process, String processControlFilename) {
|
||||||
|
|
||||||
ThreadUtils.timedWait(milliseconds, TimeUnit.MILLISECONDS.toMillis(500), new ThreadUtils.WaitCondition() {
|
ThreadUtils.timedWait(milliseconds, TimeUnit.MILLISECONDS.toMillis(500), new ThreadUtils.WaitCondition() {
|
||||||
|
|
||||||
private File processControlFile = new File(process.getWorkingDirectory(), processControlFilename);
|
private File processControlFile = new File(process.getWorkingDirectory(), processControlFilename);
|
||||||
|
|
||||||
@Override public boolean waiting() {
|
@Override
|
||||||
|
public boolean waiting() {
|
||||||
return !processControlFile.isFile();
|
return !processControlFile.isFile();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -148,7 +153,7 @@ public class GemFireDataSourceUsingNonSpringConfiguredGemFireServerIntegrationTe
|
|||||||
|
|
||||||
gemfireServer.shutdown();
|
gemfireServer.shutdown();
|
||||||
|
|
||||||
if (Boolean.valueOf(System.getProperty("spring.gemfire.fork.clean", Boolean.TRUE.toString()))) {
|
if (Boolean.valueOf(System.getProperty("spring.gemfire.fork.clean", String.valueOf(true)))) {
|
||||||
org.springframework.util.FileSystemUtils.deleteRecursively(gemfireServer.getWorkingDirectory());
|
org.springframework.util.FileSystemUtils.deleteRecursively(gemfireServer.getWorkingDirectory());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,11 +34,12 @@ import org.springframework.data.gemfire.test.support.FileSystemUtils;
|
|||||||
public class GemFireBasedServerProcess {
|
public class GemFireBasedServerProcess {
|
||||||
|
|
||||||
private static final String GEMFIRE_HTTP_SERVICE_PORT = "0";
|
private static final String GEMFIRE_HTTP_SERVICE_PORT = "0";
|
||||||
private static final String GEMFIRE_LOG_LEVEL = "warning";
|
private static final String GEMFIRE_LOG_LEVEL = "error";
|
||||||
private static final String GEMIRE_NAME = "SpringDataGemFireServer";
|
private static final String GEMIRE_NAME = "SpringDataGemFireServer";
|
||||||
private static final String GEMFIRE_USE_CLUSTER_CONFIGURATION = "false";
|
private static final String GEMFIRE_USE_CLUSTER_CONFIGURATION = "false";
|
||||||
|
|
||||||
public static void main(String[] args) throws Throwable {
|
public static void main(String[] args) throws Throwable {
|
||||||
|
|
||||||
runServer(args);
|
runServer(args);
|
||||||
|
|
||||||
registerShutdownHook();
|
registerShutdownHook();
|
||||||
@@ -50,6 +51,7 @@ public class GemFireBasedServerProcess {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static ServerLauncher runServer(String[] args) {
|
private static ServerLauncher runServer(String[] args) {
|
||||||
|
|
||||||
ServerLauncher serverLauncher = buildServerLauncher(args);
|
ServerLauncher serverLauncher = buildServerLauncher(args);
|
||||||
|
|
||||||
// start the GemFire Server process...
|
// start the GemFire Server process...
|
||||||
@@ -59,6 +61,7 @@ public class GemFireBasedServerProcess {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static ServerLauncher buildServerLauncher(String[] args) {
|
private static ServerLauncher buildServerLauncher(String[] args) {
|
||||||
|
|
||||||
return new ServerLauncher.Builder(args)
|
return new ServerLauncher.Builder(args)
|
||||||
.setMemberName(getProperty("gemfire.name", GEMIRE_NAME))
|
.setMemberName(getProperty("gemfire.name", GEMIRE_NAME))
|
||||||
.setCommand(ServerLauncher.Command.START)
|
.setCommand(ServerLauncher.Command.START)
|
||||||
@@ -80,7 +83,9 @@ public class GemFireBasedServerProcess {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void registerShutdownHook() {
|
private static void registerShutdownHook() {
|
||||||
|
|
||||||
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
||||||
|
|
||||||
ServerLauncher serverLauncher = ServerLauncher.getInstance();
|
ServerLauncher serverLauncher = ServerLauncher.getInstance();
|
||||||
|
|
||||||
if (serverLauncher != null) {
|
if (serverLauncher != null) {
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ public class ProcessWrapper {
|
|||||||
|
|
||||||
protected static final boolean DEFAULT_DAEMON_THREAD = true;
|
protected static final boolean DEFAULT_DAEMON_THREAD = true;
|
||||||
|
|
||||||
protected static final long DEFAULT_WAIT_TIME_MILLISECONDS = TimeUnit.SECONDS.toMillis(15);
|
protected static final long DEFAULT_WAIT_TIME_MILLISECONDS = TimeUnit.SECONDS.toMillis(5);
|
||||||
|
|
||||||
private final List<ProcessInputStreamListener> listeners = new CopyOnWriteArrayList<>();
|
private final List<ProcessInputStreamListener> listeners = new CopyOnWriteArrayList<>();
|
||||||
|
|
||||||
@@ -67,8 +67,8 @@ public class ProcessWrapper {
|
|||||||
private final Process process;
|
private final Process process;
|
||||||
private final ProcessConfiguration processConfiguration;
|
private final ProcessConfiguration processConfiguration;
|
||||||
|
|
||||||
/* (non-Javadoc) */
|
|
||||||
public ProcessWrapper(Process process, ProcessConfiguration processConfiguration) {
|
public ProcessWrapper(Process process, ProcessConfiguration processConfiguration) {
|
||||||
|
|
||||||
Assert.notNull(process, "Process must not be null");
|
Assert.notNull(process, "Process must not be null");
|
||||||
|
|
||||||
Assert.notNull(processConfiguration, "The context and configuration meta-data providing details"
|
Assert.notNull(processConfiguration, "The context and configuration meta-data providing details"
|
||||||
@@ -81,8 +81,8 @@ public class ProcessWrapper {
|
|||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc) */
|
|
||||||
private void init() {
|
private void init() {
|
||||||
|
|
||||||
newThread("Process OUT Stream Reader Thread",
|
newThread("Process OUT Stream Reader Thread",
|
||||||
newProcessInputStreamReaderRunnable(process.getInputStream())).start();
|
newProcessInputStreamReaderRunnable(process.getInputStream())).start();
|
||||||
|
|
||||||
@@ -92,9 +92,10 @@ public class ProcessWrapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc) */
|
|
||||||
protected Runnable newProcessInputStreamReaderRunnable(InputStream in) {
|
protected Runnable newProcessInputStreamReaderRunnable(InputStream in) {
|
||||||
|
|
||||||
return () -> {
|
return () -> {
|
||||||
|
|
||||||
if (isRunning()) {
|
if (isRunning()) {
|
||||||
BufferedReader inputReader = new BufferedReader(new InputStreamReader(in));
|
BufferedReader inputReader = new BufferedReader(new InputStreamReader(in));
|
||||||
|
|
||||||
@@ -116,8 +117,8 @@ public class ProcessWrapper {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc) */
|
|
||||||
protected Thread newThread(String name, Runnable task) {
|
protected Thread newThread(String name, Runnable task) {
|
||||||
|
|
||||||
Assert.hasText(name, "Thread name must be specified");
|
Assert.hasText(name, "Thread name must be specified");
|
||||||
Assert.notNull(task, "Thread task must not be null");
|
Assert.notNull(task, "Thread task must not be null");
|
||||||
|
|
||||||
@@ -129,38 +130,32 @@ public class ProcessWrapper {
|
|||||||
return thread;
|
return thread;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc) */
|
|
||||||
public boolean isAlive() {
|
public boolean isAlive() {
|
||||||
return ProcessUtils.isAlive(process);
|
return ProcessUtils.isAlive(process);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc) */
|
|
||||||
public boolean isNotAlive() {
|
public boolean isNotAlive() {
|
||||||
return !isAlive();
|
return !isAlive();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc) */
|
|
||||||
public List<String> getCommand() {
|
public List<String> getCommand() {
|
||||||
return processConfiguration.getCommand();
|
return processConfiguration.getCommand();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc) */
|
|
||||||
public String getCommandString() {
|
public String getCommandString() {
|
||||||
return processConfiguration.getCommandString();
|
return processConfiguration.getCommandString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc) */
|
|
||||||
public Map<String, String> getEnvironment() {
|
public Map<String, String> getEnvironment() {
|
||||||
return processConfiguration.getEnvironment();
|
return processConfiguration.getEnvironment();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc) */
|
|
||||||
public int getPid() {
|
public int getPid() {
|
||||||
return ProcessUtils.findAndReadPid(getWorkingDirectory());
|
return ProcessUtils.findAndReadPid(getWorkingDirectory());
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc) */
|
|
||||||
public int safeGetPid() {
|
public int safeGetPid() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return getPid();
|
return getPid();
|
||||||
}
|
}
|
||||||
@@ -169,33 +164,28 @@ public class ProcessWrapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc) */
|
|
||||||
public boolean isRedirectingErrorStream() {
|
public boolean isRedirectingErrorStream() {
|
||||||
return processConfiguration.isRedirectingErrorStream();
|
return processConfiguration.isRedirectingErrorStream();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc) */
|
|
||||||
public boolean isNotRunning() {
|
public boolean isNotRunning() {
|
||||||
return !isRunning();
|
return !isRunning();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc) */
|
|
||||||
public boolean isRunning() {
|
public boolean isRunning() {
|
||||||
return ProcessUtils.isRunning(process);
|
return ProcessUtils.isRunning(process);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc) */
|
|
||||||
public File getWorkingDirectory() {
|
public File getWorkingDirectory() {
|
||||||
return processConfiguration.getWorkingDirectory();
|
return processConfiguration.getWorkingDirectory();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc) */
|
|
||||||
public int exitValue() {
|
public int exitValue() {
|
||||||
return process.exitValue();
|
return process.exitValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc) */
|
|
||||||
public int safeExitValue() {
|
public int safeExitValue() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return exitValue();
|
return exitValue();
|
||||||
}
|
}
|
||||||
@@ -204,10 +194,10 @@ public class ProcessWrapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc) */
|
|
||||||
public String readLogFile() throws IOException {
|
public String readLogFile() throws IOException {
|
||||||
|
|
||||||
File[] logFiles = FileSystemUtils.listFiles(getWorkingDirectory(),
|
File[] logFiles = FileSystemUtils.listFiles(getWorkingDirectory(),
|
||||||
(path) -> (path != null && (path.isDirectory() || path.getAbsolutePath().endsWith(".log"))));
|
(path) -> path != null && (path.isDirectory() || path.getAbsolutePath().endsWith(".log")));
|
||||||
|
|
||||||
if (logFiles.length > 0) {
|
if (logFiles.length > 0) {
|
||||||
return readLogFile(logFiles[0]);
|
return readLogFile(logFiles[0]);
|
||||||
@@ -219,63 +209,63 @@ public class ProcessWrapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc) */
|
|
||||||
public String readLogFile(File log) throws IOException {
|
public String readLogFile(File log) throws IOException {
|
||||||
return FileUtils.read(log);
|
return FileUtils.read(log);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc) */
|
|
||||||
public boolean register(ProcessInputStreamListener listener) {
|
public boolean register(ProcessInputStreamListener listener) {
|
||||||
return (listener != null && listeners.add(listener));
|
return (listener != null && listeners.add(listener));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc) */
|
|
||||||
public void registerShutdownHook() {
|
public void registerShutdownHook() {
|
||||||
Runtime.getRuntime().addShutdownHook(new Thread(this::shutdown));
|
Runtime.getRuntime().addShutdownHook(new Thread(this::shutdown));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc) */
|
|
||||||
public void signal() {
|
public void signal() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
OutputStream outputStream = process.getOutputStream();
|
OutputStream outputStream = process.getOutputStream();
|
||||||
outputStream.write("\n".getBytes());
|
outputStream.write("\n".getBytes());
|
||||||
outputStream.flush();
|
outputStream.flush();
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException cause) {
|
||||||
|
|
||||||
log.warning("Failed to signal process");
|
log.warning("Failed to signal process");
|
||||||
|
|
||||||
if (log.isLoggable(Level.FINE)) {
|
if (log.isLoggable(Level.FINE)) {
|
||||||
log.fine(ThrowableUtils.toString(e));
|
log.fine(ThrowableUtils.toString(cause));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc) */
|
|
||||||
public void signalStop() {
|
public void signalStop() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ProcessUtils.signalStop(process);
|
ProcessUtils.signalStop(process);
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException cause) {
|
||||||
|
|
||||||
log.warning("Failed to signal the process to stop");
|
log.warning("Failed to signal the process to stop");
|
||||||
|
|
||||||
if (log.isLoggable(Level.FINE)) {
|
if (log.isLoggable(Level.FINE)) {
|
||||||
log.fine(ThrowableUtils.toString(e));
|
log.fine(ThrowableUtils.toString(cause));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc) */
|
|
||||||
public int stop() {
|
public int stop() {
|
||||||
return stop(DEFAULT_WAIT_TIME_MILLISECONDS);
|
return stop(DEFAULT_WAIT_TIME_MILLISECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc) */
|
|
||||||
public int stop(long milliseconds) {
|
public int stop(long milliseconds) {
|
||||||
|
|
||||||
if (isRunning()) {
|
if (isRunning()) {
|
||||||
|
|
||||||
boolean interrupted = false;
|
boolean interrupted = false;
|
||||||
int exitValue = -1;
|
int exitValue = -1;
|
||||||
int pid = safeGetPid();
|
int pid = safeGetPid();
|
||||||
long timeout = (System.currentTimeMillis() + milliseconds);
|
long timeout = System.currentTimeMillis() + milliseconds;
|
||||||
|
|
||||||
AtomicBoolean exited = new AtomicBoolean(false);
|
AtomicBoolean exited = new AtomicBoolean(false);
|
||||||
|
|
||||||
ExecutorService executorService = Executors.newSingleThreadExecutor();
|
ExecutorService executorService = Executors.newSingleThreadExecutor();
|
||||||
@@ -307,6 +297,7 @@ public class ProcessWrapper {
|
|||||||
// handles CancellationException, ExecutionException
|
// handles CancellationException, ExecutionException
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
|
|
||||||
executorService.shutdownNow();
|
executorService.shutdownNow();
|
||||||
|
|
||||||
if (interrupted) {
|
if (interrupted) {
|
||||||
@@ -321,8 +312,8 @@ public class ProcessWrapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc) */
|
|
||||||
public int shutdown() {
|
public int shutdown() {
|
||||||
|
|
||||||
if (isRunning()) {
|
if (isRunning()) {
|
||||||
log.info(String.format("Stopping process [%d]...%n", safeGetPid()));
|
log.info(String.format("Stopping process [%d]...%n", safeGetPid()));
|
||||||
signalStop();
|
signalStop();
|
||||||
@@ -332,17 +323,14 @@ public class ProcessWrapper {
|
|||||||
return stop();
|
return stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc) */
|
|
||||||
public boolean unregister(ProcessInputStreamListener listener) {
|
public boolean unregister(ProcessInputStreamListener listener) {
|
||||||
return listeners.remove(listener);
|
return listeners.remove(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc) */
|
|
||||||
public void waitFor() {
|
public void waitFor() {
|
||||||
waitFor(DEFAULT_WAIT_TIME_MILLISECONDS);
|
waitFor(DEFAULT_WAIT_TIME_MILLISECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc) */
|
|
||||||
public void waitFor(long milliseconds) {
|
public void waitFor(long milliseconds) {
|
||||||
ThreadUtils.timedWait(milliseconds, 500, this::isRunning);
|
ThreadUtils.timedWait(milliseconds, 500, this::isRunning);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,6 @@ public abstract class ProcessUtils {
|
|||||||
|
|
||||||
protected static final String TERM_TOKEN = "<TERM/>";
|
protected static final String TERM_TOKEN = "<TERM/>";
|
||||||
|
|
||||||
/* (non-Javadoc) */
|
|
||||||
public static int currentPid() {
|
public static int currentPid() {
|
||||||
RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
|
RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
|
||||||
String runtimeMXBeanName = runtimeMXBean.getName();
|
String runtimeMXBeanName = runtimeMXBean.getName();
|
||||||
@@ -75,13 +74,12 @@ public abstract class ProcessUtils {
|
|||||||
cause);
|
cause);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc) */
|
|
||||||
public static boolean isAlive(Process process) {
|
public static boolean isAlive(Process process) {
|
||||||
return (process != null && process.isAlive());
|
return process != null && process.isAlive();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc) */
|
|
||||||
public static boolean isRunning(int processId) {
|
public static boolean isRunning(int processId) {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
for (VirtualMachineDescriptor vmDescriptor : VirtualMachine.list()) {
|
for (VirtualMachineDescriptor vmDescriptor : VirtualMachine.list()) {
|
||||||
if (String.valueOf(processId).equals(vmDescriptor.id())) {
|
if (String.valueOf(processId).equals(vmDescriptor.id())) {
|
||||||
@@ -95,8 +93,8 @@ public abstract class ProcessUtils {
|
|||||||
throw new UnsupportedOperationException("operation not supported");
|
throw new UnsupportedOperationException("operation not supported");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc) */
|
|
||||||
public static boolean isRunning(Process process) {
|
public static boolean isRunning(Process process) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
process.exitValue();
|
process.exitValue();
|
||||||
return false;
|
return false;
|
||||||
@@ -106,8 +104,8 @@ public abstract class ProcessUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc) */
|
|
||||||
public static void signalStop(Process process) throws IOException {
|
public static void signalStop(Process process) throws IOException {
|
||||||
|
|
||||||
if (isRunning(process)) {
|
if (isRunning(process)) {
|
||||||
OutputStream processOutputStream = process.getOutputStream();
|
OutputStream processOutputStream = process.getOutputStream();
|
||||||
processOutputStream.write(TERM_TOKEN.concat("\n").getBytes());
|
processOutputStream.write(TERM_TOKEN.concat("\n").getBytes());
|
||||||
@@ -115,14 +113,12 @@ public abstract class ProcessUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc) */
|
|
||||||
@SuppressWarnings("all")
|
@SuppressWarnings("all")
|
||||||
public static void waitForStopSignal() {
|
public static void waitForStopSignal() {
|
||||||
Scanner in = new Scanner(System.in);
|
Scanner in = new Scanner(System.in);
|
||||||
while (!TERM_TOKEN.equals(in.next()));
|
while (!TERM_TOKEN.equals(in.next()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc) */
|
|
||||||
public static int findAndReadPid(File workingDirectory) {
|
public static int findAndReadPid(File workingDirectory) {
|
||||||
File pidFile = findPidFile(workingDirectory);
|
File pidFile = findPidFile(workingDirectory);
|
||||||
|
|
||||||
@@ -135,9 +131,9 @@ public abstract class ProcessUtils {
|
|||||||
return readPid(pidFile);
|
return readPid(pidFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc) */
|
|
||||||
@SuppressWarnings("all")
|
@SuppressWarnings("all")
|
||||||
protected static File findPidFile(File workingDirectory) {
|
protected static File findPidFile(File workingDirectory) {
|
||||||
|
|
||||||
Assert.isTrue(FileSystemUtils.isDirectory(workingDirectory), String.format(
|
Assert.isTrue(FileSystemUtils.isDirectory(workingDirectory), String.format(
|
||||||
"File [%s] is not a valid directory", workingDirectory));
|
"File [%s] is not a valid directory", workingDirectory));
|
||||||
|
|
||||||
@@ -154,9 +150,9 @@ public abstract class ProcessUtils {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc) */
|
|
||||||
@SuppressWarnings("all")
|
@SuppressWarnings("all")
|
||||||
public static int readPid(File pidFile) {
|
public static int readPid(File pidFile) {
|
||||||
|
|
||||||
Assert.isTrue(pidFile != null && pidFile.isFile(), String.format(
|
Assert.isTrue(pidFile != null && pidFile.isFile(), String.format(
|
||||||
"File [%s] is not a valid file", pidFile));
|
"File [%s] is not a valid file", pidFile));
|
||||||
|
|
||||||
@@ -184,9 +180,9 @@ public abstract class ProcessUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc) */
|
|
||||||
@SuppressWarnings("all")
|
@SuppressWarnings("all")
|
||||||
public static void writePid(File pidFile, int pid) throws IOException {
|
public static void writePid(File pidFile, int pid) throws IOException {
|
||||||
|
|
||||||
Assert.isTrue(pidFile != null && (pidFile.isFile() || pidFile.createNewFile()), String.format(
|
Assert.isTrue(pidFile != null && (pidFile.isFile() || pidFile.createNewFile()), String.format(
|
||||||
"File [%s] is not a valid file", pidFile));
|
"File [%s] is not a valid file", pidFile));
|
||||||
|
|
||||||
@@ -203,7 +199,6 @@ public abstract class ProcessUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc) */
|
|
||||||
protected static class DirectoryPidFileFilter extends PidFileFilter {
|
protected static class DirectoryPidFileFilter extends PidFileFilter {
|
||||||
|
|
||||||
protected static final DirectoryPidFileFilter INSTANCE = new DirectoryPidFileFilter();
|
protected static final DirectoryPidFileFilter INSTANCE = new DirectoryPidFileFilter();
|
||||||
@@ -213,11 +208,10 @@ public abstract class ProcessUtils {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean accept(File path) {
|
public boolean accept(File path) {
|
||||||
return (path != null && (path.isDirectory() || super.accept(path)));
|
return path != null && (path.isDirectory() || super.accept(path));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc) */
|
|
||||||
protected static class PidFileFilter implements FileFilter {
|
protected static class PidFileFilter implements FileFilter {
|
||||||
|
|
||||||
protected static final PidFileFilter INSTANCE = new PidFileFilter();
|
protected static final PidFileFilter INSTANCE = new PidFileFilter();
|
||||||
@@ -227,7 +221,7 @@ public abstract class ProcessUtils {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean accept(File path) {
|
public boolean accept(File path) {
|
||||||
return (path != null && path.isFile() && path.getName().toLowerCase().endsWith(".pid"));
|
return path != null && path.isFile() && path.getName().toLowerCase().endsWith(".pid");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ import java.util.concurrent.TimeUnit;
|
|||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public abstract class ThreadUtils {
|
public abstract class ThreadUtils {
|
||||||
|
|
||||||
/* (non-Javadoc) */
|
|
||||||
public static boolean sleep(long milliseconds) {
|
public static boolean sleep(long milliseconds) {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(milliseconds);
|
Thread.sleep(milliseconds);
|
||||||
@@ -54,18 +53,19 @@ public abstract class ThreadUtils {
|
|||||||
|
|
||||||
@SuppressWarnings("all")
|
@SuppressWarnings("all")
|
||||||
public static boolean timedWait(long duration, long interval, WaitCondition waitCondition) {
|
public static boolean timedWait(long duration, long interval, WaitCondition waitCondition) {
|
||||||
final long timeout = (System.currentTimeMillis() + duration);
|
|
||||||
|
final long timeout = System.currentTimeMillis() + duration;
|
||||||
|
|
||||||
interval = Math.min(interval, duration);
|
interval = Math.min(interval, duration);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
while (waitCondition.waiting() && (System.currentTimeMillis() < timeout)) {
|
while (waitCondition.waiting() && System.currentTimeMillis() < timeout) {
|
||||||
synchronized (waitCondition) {
|
synchronized (waitCondition) {
|
||||||
TimeUnit.MILLISECONDS.timedWait(waitCondition, interval);
|
TimeUnit.MILLISECONDS.timedWait(waitCondition, interval);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (InterruptedException e) {
|
catch (InterruptedException cause) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,9 @@
|
|||||||
# java.util.logging (JUL) configuration
|
# java.util.logging (JUL) configuration
|
||||||
|
|
||||||
|
java.util.logging.MemoryHandler.level=OFF
|
||||||
|
java.util.logging.MemoryHandler.size=1
|
||||||
|
|
||||||
org.apache=ERROR
|
org.apache=ERROR
|
||||||
org.springframework=ERROR
|
org.springframework=ERROR
|
||||||
|
org.springframework.data.gemfire.support.SpringContextBootstrappingInitializer=OFF
|
||||||
|
org.springframework.data.gemfire.support.SpringContextBootstrappingInitializer.handlers=java.util.logging.MemoryHandler
|
||||||
|
|||||||
@@ -6,11 +6,14 @@
|
|||||||
<File name="File" fileName="build/logs/spring-test.log">
|
<File name="File" fileName="build/logs/spring-test.log">
|
||||||
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{1.} - %msg%n"/>
|
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{1.} - %msg%n"/>
|
||||||
</File>
|
</File>
|
||||||
|
<Null name="nop"/>
|
||||||
</Appenders>
|
</Appenders>
|
||||||
<Loggers>
|
<Loggers>
|
||||||
<Logger name="org.apache.geode" level="error"/>
|
<Logger name="org.apache.geode" level="error"/>
|
||||||
<Logger name="org.springframework" level="error"/>
|
<Logger name="org.springframework" level="error"/>
|
||||||
<Logger name="org.springframework.data.gemfire.support.SpringContextBootstrappingInitializer" level="off"/>
|
<Logger name="org.springframework.data.gemfire.support.SpringContextBootstrappingInitializer" level="off">
|
||||||
|
<AppenderRef ref="nop"/>
|
||||||
|
</Logger>
|
||||||
<Root level="error">
|
<Root level="error">
|
||||||
<AppenderRef ref="Console"/>
|
<AppenderRef ref="Console"/>
|
||||||
<!--AppenderRef ref="File" /-->
|
<!--AppenderRef ref="File" /-->
|
||||||
|
|||||||
@@ -9,6 +9,8 @@
|
|||||||
</encoder>
|
</encoder>
|
||||||
</appender>
|
</appender>
|
||||||
|
|
||||||
|
<appender name="nop" class="ch.qos.logback.core.helpers.NOPAppender"/>
|
||||||
|
|
||||||
<appender name="testAppender" class="org.springframework.data.gemfire.test.logging.slf4j.logback.TestAppender">
|
<appender name="testAppender" class="org.springframework.data.gemfire.test.logging.slf4j.logback.TestAppender">
|
||||||
<encoder>
|
<encoder>
|
||||||
<pattern>TEST - %m%n</pattern>
|
<pattern>TEST - %m%n</pattern>
|
||||||
@@ -23,6 +25,10 @@
|
|||||||
<appender-ref ref="testAppender"/>
|
<appender-ref ref="testAppender"/>
|
||||||
</logger>
|
</logger>
|
||||||
|
|
||||||
|
<logger name="org.springframework.data.gemfire.support.SpringContextBootstrappingInitializer" level="off">
|
||||||
|
<appender-ref ref="nop"/>
|
||||||
|
</logger>
|
||||||
|
|
||||||
<root level="${logback.log.level:-ERROR}">
|
<root level="${logback.log.level:-ERROR}">
|
||||||
<appender-ref ref="console"/>
|
<appender-ref ref="console"/>
|
||||||
</root>
|
</root>
|
||||||
|
|||||||
Reference in New Issue
Block a user