Github user kirklund commented on a diff in the pull request:

    https://github.com/apache/geode/pull/699#discussion_r132542169
  
    --- Diff: 
geode-core/src/test/java/org/apache/geode/distributed/ServerLauncherRemoteIntegrationTestCase.java
 ---
    @@ -0,0 +1,270 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more 
contributor license
    + * agreements. See the NOTICE file distributed with this work for 
additional information regarding
    + * copyright ownership. The ASF licenses this file to You under the Apache 
License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance with the 
License. You may obtain a
    + * copy of the License at
    + *
    + * http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software 
distributed under the License
    + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 
ANY KIND, either express
    + * or implied. See the License for the specific language governing 
permissions and limitations under
    + * the License.
    + */
    +package org.apache.geode.distributed;
    +
    +import static java.util.concurrent.TimeUnit.MINUTES;
    +import static 
org.apache.geode.distributed.ConfigurationProperties.LOG_LEVEL;
    +import static 
org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
    +import static 
org.apache.geode.distributed.internal.DistributionConfig.GEMFIRE_PREFIX;
    +import static 
org.apache.geode.internal.cache.AbstractCacheServer.TEST_OVERRIDE_DEFAULT_PORT_PROPERTY;
    +import static 
org.apache.geode.internal.process.ProcessUtils.isProcessAlive;
    +import static org.assertj.core.api.Assertions.assertThat;
    +
    +import java.io.File;
    +import java.io.IOException;
    +import java.io.UncheckedIOException;
    +import java.net.BindException;
    +import java.util.ArrayList;
    +import java.util.List;
    +import java.util.concurrent.atomic.AtomicBoolean;
    +
    +import org.junit.After;
    +import org.junit.Before;
    +
    +import org.apache.geode.distributed.AbstractLauncher.Status;
    +import org.apache.geode.internal.process.ProcessStreamReader;
    +import org.apache.geode.internal.process.ProcessStreamReader.InputListener;
    +
    +/**
    + * Abstract base class for integration tests of {@link ServerLauncher} as 
an application main in a
    + * forked JVM.
    + *
    + * @since GemFire 8.0
    + */
    +public abstract class ServerLauncherRemoteIntegrationTestCase
    +    extends ServerLauncherIntegrationTestCase implements UsesServerCommand 
{
    +
    +  private final AtomicBoolean threwBindException = new AtomicBoolean();
    +
    +  protected volatile Process process;
    +  protected volatile ProcessStreamReader processOutReader;
    +  protected volatile ProcessStreamReader processErrReader;
    +
    +  private ServerCommand serverCommand;
    +
    +  @Before
    +  public void setUp() throws Exception {
    +    serverCommand = new ServerCommand(this);
    +  }
    +
    +  @After
    +  public void tearDownAbstractServerLauncherRemoteIntegrationTestCase() 
throws Exception {
    +    if (this.process != null) {
    +      this.process.destroy();
    +      this.process = null;
    +    }
    +    if (this.processOutReader != null && 
this.processOutReader.isRunning()) {
    +      this.processOutReader.stop();
    +    }
    +    if (this.processErrReader != null && 
this.processErrReader.isRunning()) {
    +      this.processErrReader.stop();
    +    }
    +  }
    +
    +  @Override
    +  public List<String> getJvmArguments() {
    +    List<String> jvmArguments = new ArrayList<>();
    +    jvmArguments.add("-D" + GEMFIRE_PREFIX + LOG_LEVEL + "=config");
    +    jvmArguments.add("-D" + GEMFIRE_PREFIX + MCAST_PORT + "=0");
    +    jvmArguments
    +        .add("-D" + TEST_OVERRIDE_DEFAULT_PORT_PROPERTY + "=" + 
String.valueOf(defaultServerPort));
    +    return jvmArguments;
    +  }
    +
    +  @Override
    +  public String getName() {
    +    return getUniqueName();
    +  }
    +
    +  @Override
    +  public boolean getDisableDefaultServer() {
    +    return false;
    +  }
    +
    +  protected void assertThatServerThrewBindException() {
    +    assertThat(threwBindException.get()).isTrue();
    +  }
    +
    +  protected void assertThatServerThrew(final Class<? extends Throwable> 
throwableClass) {
    +    assertThat(threwBindException.get()).isTrue();
    +  }
    +
    +  protected ServerLauncher startServer(final ServerCommand command) {
    +    return awaitStart(command);
    +  }
    +
    +  protected ServerLauncher awaitStart(final ServerCommand command,
    +      final ProcessStreamReader.InputListener outListener,
    +      final ProcessStreamReader.InputListener errListener) throws 
Exception {
    +    executeCommandWithReaders(command.create(), outListener, errListener);
    +    ServerLauncher launcher = awaitStart(getWorkingDirectory());
    +    assertThat(process.isAlive()).isTrue();
    +    return launcher;
    +  }
    +
    +  protected ServerLauncher awaitStart(final ServerCommand command) {
    +    try {
    +      executeCommandWithReaders(command);
    +      ServerLauncher launcher = awaitStart(getWorkingDirectory());
    +      assertThat(process.isAlive()).isTrue();
    +      return launcher;
    +    } catch (IOException e) {
    +      throw new UncheckedIOException(e);
    +    }
    +  }
    +
    +  protected ServerLauncher awaitStart(final File workingDirectory) {
    +    try {
    +      this.launcher = new ServerLauncher.Builder()
    +          
.setWorkingDirectory(workingDirectory.getCanonicalPath()).build();
    +      ServerLauncher launcher = awaitStart(this.launcher);
    +      assertThat(process.isAlive()).isTrue();
    +      return launcher;
    +    } catch (IOException e) {
    +      throw new UncheckedIOException(e);
    +    }
    +  }
    +
    +  @Override
    +  protected ServerLauncher awaitStart(final ServerLauncher launcher) {
    +    await().until(() -> 
assertThat(launcher.status().getStatus()).isEqualTo(Status.ONLINE));
    +    assertThat(process.isAlive()).isTrue();
    +    return launcher;
    +  }
    +
    +  protected ServerLauncher awaitStart() {
    +    return awaitStart(this.launcher);
    +  }
    +
    +  protected void awaitStop() {
    +    await().until(() -> assertThat(this.process.isAlive()).isFalse());
    +  }
    +
    +  protected void assertStopOf(final Process process) {
    +    await().until(() -> assertThat(process.isAlive()).isFalse());
    +  }
    +
    +  protected Process getServerProcess() {
    +    return this.process;
    +  }
    +
    +  protected void startServerShouldFail(final ServerCommand command, final 
InputListener outListener,
    +      final InputListener errListener) throws IOException, 
InterruptedException {
    +    executeCommandWithReaders(command.create(), outListener, errListener);
    +    process.waitFor(2, MINUTES);
    +    assertThat(process.isAlive()).isFalse();
    +    assertThat(process.exitValue()).isEqualTo(1);
    +  }
    +
    +  protected void startServerShouldFail(final ServerCommand command)
    +      throws IOException, InterruptedException {
    +    startServerShouldFail(command, createBindExceptionListener("sysout", 
threwBindException),
    +        createBindExceptionListener("syserr", threwBindException));
    +  }
    +
    +  protected void startServerShouldFail() throws IOException, 
InterruptedException {
    +    startServerShouldFail(serverCommand);
    +  }
    +
    +  private InputListener createBindExceptionListener(final String name,
    +      final AtomicBoolean threwBindException) {
    +    return createExpectedListener(name, getUniqueName() + "#" + name, 
BindException.class.getName(),
    +        threwBindException);
    +  }
    +
    +  @Override
    +  protected ServerLauncher startServer() {
    +    return startServer(serverCommand);
    +  }
    +
    +  protected void assertThatProcessIsNotAlive() {
    --- End diff --
    
    All unused methods deleted.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to