Skip to content
Merged
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 @@ -15,10 +15,8 @@
package org.apache.geode.management.internal.cli.commands;

import static org.apache.geode.distributed.ConfigurationProperties.GROUPS;
import static org.apache.geode.internal.lang.SystemUtils.isWindows;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assume.assumeFalse;

import java.io.File;
import java.io.Serializable;
Expand All @@ -41,7 +39,6 @@
* @since GemFire 7.0
*/
@SuppressWarnings("serial")

public class DeployWithGroupsDUnitTest implements Serializable {
private static final String GROUP1 = "Group1";
private static final String GROUP2 = "Group2";
Expand Down Expand Up @@ -201,8 +198,6 @@ public void deployJarToAllServers() throws Exception {

@Test
public void deployJarToAllServersWithRestart() {
// TODO: Ignore on windows until GEODE-5787
assumeFalse(isWindows());
// Deploy a jar to all servers
gfshConnector.executeAndAssertThat("deploy --jar=" + jar1).statusIsSuccess();
String resultString = gfshConnector.getGfshOutput();
Expand Down Expand Up @@ -231,8 +226,6 @@ public void deployJarToAllServersWithRestart() {

@Test
public void undeployJarFromAllServersWithRestart() throws Exception {
// TODO: Ignore on windows until GEODE-5787
assumeFalse(isWindows());
// Deploy a jar to all servers
gfshConnector.executeAndAssertThat("deploy --jar=" + jar1).statusIsSuccess();
String resultString = gfshConnector.getGfshOutput();
Expand Down
12 changes: 8 additions & 4 deletions geode-dunit/src/main/java/org/apache/geode/test/dunit/Host.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import java.util.ArrayList;
import java.util.List;

import org.apache.geode.test.dunit.internal.ChildVMLauncher;
import org.apache.geode.test.dunit.internal.ProcessHolder;
import org.apache.geode.test.dunit.internal.RemoteDUnitVMIF;
import org.apache.geode.test.version.VersionManager;

Expand Down Expand Up @@ -162,8 +164,9 @@ public VM getVM(String version, int n) {
/**
* Adds a VM to this {@code Host} with the given process id and client record.
*/
protected void addVM(int vmid, RemoteDUnitVMIF client) {
VM vm = new VM(this, vmid, client);
protected void addVM(int vmid, RemoteDUnitVMIF client, ProcessHolder processHolder,
ChildVMLauncher childVMLauncher) {
VM vm = new VM(this, vmid, client, processHolder, childVMLauncher);
vms.add(vm);
}

Expand All @@ -175,8 +178,9 @@ private static void setLocator(VM l) {
locator = l;
}

protected void addLocator(int vmid, RemoteDUnitVMIF client) {
setLocator(new VM(this, vmid, client));
protected void addLocator(int vmid, RemoteDUnitVMIF client, ProcessHolder processHolder,
ChildVMLauncher childVMLauncher) {
setLocator(new VM(this, vmid, client, processHolder, childVMLauncher));
}

@Override
Expand Down
146 changes: 80 additions & 66 deletions geode-dunit/src/main/java/org/apache/geode/test/dunit/VM.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,20 @@
import static org.apache.geode.test.dunit.internal.DUnitLauncher.NUM_VMS;

import java.io.File;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.Serializable;
import java.io.StringWriter;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.util.List;
import java.util.concurrent.Callable;

import org.apache.logging.log4j.Logger;

import org.apache.geode.internal.logging.LogService;
import org.apache.geode.internal.process.ProcessUtils;
import org.apache.geode.test.dunit.internal.BounceResult;
import org.apache.geode.test.dunit.internal.ChildVMLauncher;
import org.apache.geode.test.dunit.internal.MethodInvokerResult;
import org.apache.geode.test.dunit.internal.ProcessHolder;
import org.apache.geode.test.dunit.internal.RemoteDUnitVMIF;
import org.apache.geode.test.dunit.internal.StandAloneDUnitEnv;
import org.apache.geode.test.version.VersionManager;
Expand All @@ -37,6 +41,8 @@
@SuppressWarnings("serial,unused")
public class VM implements Serializable {

private static final Logger logger = LogService.getLogger();

public static final int CONTROLLER_VM = -1;

public static final int DEFAULT_VM_COUNT = NUM_VMS;
Expand All @@ -56,6 +62,10 @@ public class VM implements Serializable {
/** The state of this VM */
private volatile boolean available;

private transient volatile ProcessHolder processHolder;

private transient ChildVMLauncher childVMLauncher;

/**
* Returns the {@code VM} identity. For {@link StandAloneDUnitEnv} the number returned is a
* zero-based sequence representing the order in with the DUnit {@code VM}s were launched.
Expand Down Expand Up @@ -146,15 +156,19 @@ public static VM[] toArray(VM... vms) {
/**
* Creates a new {@code VM} that runs on a given host with a given process id.
*/
public VM(final Host host, final int id, final RemoteDUnitVMIF client) {
this(host, VersionManager.CURRENT_VERSION, id, client);
public VM(final Host host, final int id, final RemoteDUnitVMIF client,
final ProcessHolder processHolder, final ChildVMLauncher childVMLauncher) {
this(host, VersionManager.CURRENT_VERSION, id, client, processHolder, childVMLauncher);
}

public VM(final Host host, final String version, final int id, final RemoteDUnitVMIF client) {
public VM(final Host host, final String version, final int id, final RemoteDUnitVMIF client,
final ProcessHolder processHolder, final ChildVMLauncher childVMLauncher) {
this.host = host;
this.id = id;
this.version = version;
this.client = client;
this.processHolder = processHolder;
this.childVMLauncher = childVMLauncher;
available = true;
}

Expand Down Expand Up @@ -202,7 +216,8 @@ public int getPid() {
*/
@Deprecated
public <V> V invoke(final Class<?> targetClass, final String methodName) {
return invoke(targetClass, methodName, new Object[0]);
checkAvailability(targetClass.getName(), methodName);
return executeMethodOnClass(targetClass, methodName, new Object[0]);
}

/**
Expand Down Expand Up @@ -234,20 +249,8 @@ public <V> AsyncInvocation<V> invokeAsync(final Class<?> targetClass, final Stri
*/
@Deprecated
public <V> V invoke(final Class<?> targetClass, final String methodName, final Object[] args) {
if (!available) {
throw new RMIException(this, targetClass.getName(), methodName,
new IllegalStateException("VM not available: " + this));
}

MethodInvokerResult result = execute(targetClass, methodName, args);

if (!result.exceptionOccurred()) {
return (V) result.getResult();

} else {
throw new RMIException(this, targetClass.getName(), methodName, result.getException(),
result.getStackTrace());
}
checkAvailability(targetClass.getName(), methodName);
return executeMethodOnClass(targetClass, methodName, args);
}

/**
Expand Down Expand Up @@ -345,7 +348,8 @@ public <V> AsyncInvocation<V> invokeAsync(final SerializableCallableIF<V> callab
* @see SerializableRunnable
*/
public void invoke(final String name, final SerializableRunnableIF runnable) {
invoke(new NamedRunnable(name, runnable), "run");
checkAvailability(NamedRunnable.class.getName(), "run");
executeMethodOnObject(new NamedRunnable(name, runnable), "run", new Object[0]);
}

/**
Expand All @@ -357,7 +361,8 @@ public void invoke(final String name, final SerializableRunnableIF runnable) {
* @see SerializableRunnable
*/
public void invoke(final SerializableRunnableIF runnable) {
invoke(runnable, "run");
checkAvailability(runnable.getClass().getName(), "run");
executeMethodOnObject(runnable, "run", new Object[0]);
}

/**
Expand All @@ -369,7 +374,8 @@ public void invoke(final SerializableRunnableIF runnable) {
* @see SerializableCallable
*/
public <V> V invoke(final String name, final SerializableCallableIF<V> callable) {
return invoke(new NamedCallable<>(name, callable), "call");
checkAvailability(NamedCallable.class.getName(), "call");
return executeMethodOnObject(new NamedCallable<>(name, callable), "call", new Object[0]);
}

/**
Expand All @@ -380,7 +386,8 @@ public <V> V invoke(final String name, final SerializableCallableIF<V> callable)
* @see SerializableCallable
*/
public <V> V invoke(final SerializableCallableIF<V> callable) {
return invoke(callable, "call");
checkAvailability(callable.getClass().getName(), "call");
return executeMethodOnObject(callable, "call", new Object[0]);
}

/**
Expand All @@ -398,7 +405,8 @@ public <V> V invoke(final SerializableCallableIF<V> callable) {
*/
@Deprecated
public <V> V invoke(final Object targetObject, final String methodName) {
return invoke(targetObject, methodName, new Object[0]);
checkAvailability(targetObject.getClass().getName(), methodName);
return executeMethodOnObject(targetObject, methodName, new Object[0]);
}

/**
Expand All @@ -417,20 +425,8 @@ public <V> V invoke(final Object targetObject, final String methodName) {
*/
@Deprecated
public <V> V invoke(final Object targetObject, final String methodName, final Object[] args) {
if (!available) {
throw new RMIException(this, targetObject.getClass().getName(), methodName,
new IllegalStateException("VM not available: " + this));
}

MethodInvokerResult result = execute(targetObject, methodName, args);

if (!result.exceptionOccurred()) {
return (V) result.getResult();

} else {
throw new RMIException(this, targetObject.getClass().getName(), methodName,
result.getException(), result.getStackTrace());
}
checkAvailability(targetObject.getClass().getName(), methodName);
return executeMethodOnObject(targetObject, methodName, args);
}

/**
Expand Down Expand Up @@ -481,28 +477,40 @@ public void bounce(final String targetVersion) {
}

private synchronized void bounce(final String targetVersion, boolean force) {
if (!available) {
throw new RMIException(this, getClass().getName(), "bounceVM",
new IllegalStateException("VM not available: " + this));
}
checkAvailability(getClass().getName(), "bounceVM");

logger.info("Bouncing {} old pid is {}", id, getPid());
available = false;

try {
BounceResult result = DUnitEnv.get().bounce(targetVersion, id, force);
id = result.getNewId();
client = result.getNewClient();
if (force) {
processHolder.killForcibly();
} else {
SerializableRunnableIF runnable = () -> new Thread(() -> {
try {
// sleep before exit so that the rmi call is returned
Thread.sleep(100);
System.exit(0);
} catch (InterruptedException e) {
logger.error("VM bounce thread interrupted before exiting.", e);
}
}).start();
executeMethodOnObject(runnable, "run", new Object[0]);
}
processHolder.waitFor();
processHolder = childVMLauncher.launchVM(targetVersion, id, true);
version = targetVersion;
client = childVMLauncher.getStub(id);
available = true;
logger.info("Bounced {} new pid is {}", id, getPid());
} catch (InterruptedException | IOException | NotBoundException e) {
throw new Error("Unable to restart VM " + id, e);
}
}

} catch (UnsupportedOperationException e) {
available = true;
throw e;

} catch (RemoteException e) {
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw, true));
throw new RMIException(this, getClass().getName(), "bounceVM", e, sw.toString());
private void checkAvailability(String className, String methodName) {
if (!available) {
throw new RMIException(this, className, methodName,
new IllegalStateException("VM not available: " + this));
}
}

Expand All @@ -516,26 +524,32 @@ public String toString() {
+ (VersionManager.isCurrentVersion(version) ? "" : (" with version " + version));
}

private MethodInvokerResult execute(final Class<?> targetClass, final String methodName,
private <V> V executeMethodOnObject(final Object targetObject, final String methodName,
final Object[] args) {
try {
return client.executeMethodOnClass(targetClass.getName(), methodName, args);
MethodInvokerResult result = client.executeMethodOnObject(targetObject, methodName, args);
if (result.exceptionOccurred()) {
throw new RMIException(this, targetObject.getClass().getName(), methodName,
result.getException(), result.getStackTrace());
}
return (V) result.getResult();
} catch (RemoteException exception) {
throw new RMIException(this, targetClass.getName(), methodName, exception);
throw new RMIException(this, targetObject.getClass().getName(), methodName, exception);
}
}

private MethodInvokerResult execute(final Object targetObject, final String methodName,
private <V> V executeMethodOnClass(final Class<?> targetClass, final String methodName,
final Object[] args) {
try {
if (args == null) {
return client.executeMethodOnObject(targetObject, methodName);
} else {
return client.executeMethodOnObject(targetObject, methodName, args);
MethodInvokerResult result =
client.executeMethodOnClass(targetClass.getName(), methodName, args);
if (result.exceptionOccurred()) {
throw new RMIException(this, targetClass.getName(), methodName, result.getException(),
result.getStackTrace());
}
return (V) result.getResult();
} catch (RemoteException exception) {
throw new RMIException(this, targetObject.getClass().getName(), methodName, exception);
throw new RMIException(this, targetClass.getName(), methodName, exception);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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.test.dunit.internal;

import java.io.IOException;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;

public interface ChildVMLauncher {

ProcessHolder launchVM(String version, int vmNum, boolean bouncedVM)
throws IOException;

RemoteDUnitVMIF getStub(int i) throws RemoteException, NotBoundException, InterruptedException;
}
Loading