use of org.apache.ignite.testframework.junits.multijvm.IgniteProcessProxy in project ignite by apache.
the class IgniteCompatibilityAbstractTest method startGrid.
/**
* Starts new Ignite instance of given version and name <b>in separate JVM</b>.
*
* Uses an ignite-core artifact in the Maven local repository, if it isn't exists there, it will be downloaded and
* stored via Maven.
*
* @param igniteInstanceName Instance name.
* @param ver Ignite version. Dots separated, 3-digit version.
* @param cfgClo IgniteInClosure for post-configuration.
* @param clo IgniteInClosure for actions on started Ignite.
* @return Started grid.
* @throws Exception In case of an error.
*/
protected IgniteEx startGrid(final String igniteInstanceName, final String ver, IgniteInClosure<IgniteConfiguration> cfgClo, IgniteInClosure<Ignite> clo) throws Exception {
assert isMultiJvm() : "MultiJvm mode must be switched on for the node stop properly.";
assert !igniteInstanceName.equals(getTestIgniteInstanceName(0)) : "Use default instance name for local nodes only.";
final String cfgCloPath = IgniteCompatibilityNodeRunner.storeToFile(cfgClo);
final String cloPath = IgniteCompatibilityNodeRunner.storeToFile(clo);
// stub - won't be used at node startup
final IgniteConfiguration cfg = getConfiguration(igniteInstanceName);
IgniteProcessProxy ignite = new IgniteProcessProxy(cfg, log, locJvmInstance, true) {
@Override
protected IgniteLogger logger(IgniteLogger log, Object ctgr) {
return ListenedGridTestLog4jLogger.createLogger(ctgr + "#" + ver.replaceAll("\\.", "_"));
}
@Override
protected String igniteNodeRunnerClassName() throws Exception {
return IgniteCompatibilityNodeRunner.class.getCanonicalName();
}
@Override
protected String params(IgniteConfiguration cfg, boolean resetDiscovery) throws Exception {
return cfgCloPath + " " + igniteInstanceName + " " + getId() + " " + (rmJvmInstance == null ? getId() : ((IgniteProcessProxy) rmJvmInstance).getId()) + (cloPath == null ? "" : " " + cloPath);
}
@Override
protected Collection<String> filteredJvmArgs() throws Exception {
Collection<String> filteredJvmArgs = new ArrayList<>();
filteredJvmArgs.add("-ea");
for (String arg : U.jvmArgs()) {
if (arg.startsWith("-Xmx") || arg.startsWith("-Xms"))
filteredJvmArgs.add(arg);
}
ClassLoader ldr = CLASS_LOADER;
final Collection<Dependency> dependencies = getDependencies(ver);
StringBuilder pathBuilder = new StringBuilder();
for (URL url : IgniteUtils.classLoaderUrls(ldr)) {
String path = url.getPath();
boolean excluded = false;
for (Dependency next : dependencies) {
if (path.contains(next.localPathTemplate())) {
excluded = true;
break;
}
}
if (!excluded)
pathBuilder.append(path).append(File.pathSeparator);
}
for (Dependency next : dependencies) {
final String artifactVer = next.version() != null ? next.version() : ver;
final String grpName = next.groupName() != null ? next.groupName() : "org.apache.ignite";
String pathToArtifact = MavenUtils.getPathToIgniteArtifact(grpName, next.artifactName(), artifactVer, next.classifier());
pathBuilder.append(pathToArtifact).append(File.pathSeparator);
}
filteredJvmArgs.add("-cp");
filteredJvmArgs.add(pathBuilder.toString());
final Collection<String> jvmParms = getJvmParms();
if (jvmParms != null)
filteredJvmArgs.addAll(jvmParms);
return filteredJvmArgs;
}
};
if (locJvmInstance == null) {
CountDownLatch nodeJoinedLatch = new CountDownLatch(1);
UUID nodeId = ignite.getId();
ListenedGridTestLog4jLogger log = (ListenedGridTestLog4jLogger) ignite.log();
log.addListener(nodeId, new LoggedJoinNodeClosure(nodeJoinedLatch, nodeId));
final long nodeJoinTimeout = getNodeJoinTimeout();
final boolean joined = nodeJoinedLatch.await(nodeJoinTimeout, TimeUnit.MILLISECONDS);
assertTrue("Node has not joined [id=" + nodeId + "]/" + "or does not completed its startup during timeout: " + nodeJoinTimeout + " ms.", joined);
log.removeListener(nodeId);
}
if (rmJvmInstance == null)
rmJvmInstance = ignite;
return ignite;
}
use of org.apache.ignite.testframework.junits.multijvm.IgniteProcessProxy in project ignite by apache.
the class GridAbstractTest method stopGrid.
/**
* @param igniteInstanceName Ignite instance name.
* @param cancel Cancel flag.
* @param awaitTop Await topology change flag.
*/
@SuppressWarnings({ "deprecation" })
protected void stopGrid(@Nullable String igniteInstanceName, boolean cancel, boolean awaitTop) {
try {
IgniteEx ignite = grid(igniteInstanceName);
assert ignite != null : "Ignite returned null grid for name: " + igniteInstanceName;
UUID id = ignite instanceof IgniteProcessProxy ? ignite.localNode().id() : ignite.context().localNodeId();
info(">>> Stopping grid [name=" + ignite.name() + ", id=" + id + ']');
if (!isRemoteJvm(igniteInstanceName))
G.stop(igniteInstanceName, cancel);
else
IgniteProcessProxy.stop(igniteInstanceName, cancel);
if (awaitTop)
awaitTopologyChange();
} catch (IllegalStateException ignored) {
// Ignore error if grid already stopped.
} catch (Throwable e) {
error("Failed to stop grid [igniteInstanceName=" + igniteInstanceName + ", cancel=" + cancel + ']', e);
stopGridErr = true;
}
}
use of org.apache.ignite.testframework.junits.multijvm.IgniteProcessProxy in project ignite by apache.
the class IgniteCompatibilityAbstractTest method startGrid.
/**
* {@inheritDoc}
*/
@Override
protected Ignite startGrid(String igniteInstanceName, IgniteConfiguration cfg, GridSpringResourceContext ctx) throws Exception {
final Ignite ignite;
// in IgniteProcessProxy constructor.
if (locJvmInstance == null && rmJvmInstance != null) {
final UUID nodeId = cfg.getNodeId();
final UUID syncNodeId = ((IgniteProcessProxy) rmJvmInstance).getId();
ignite = super.startGrid(igniteInstanceName, cfg, ctx);
assert ignite.configuration().getNodeId() == nodeId : "Started node has unexpected node id.";
assert ignite.cluster().node(syncNodeId) != null : "Node has not joined [id=" + nodeId + "]";
} else
ignite = super.startGrid(igniteInstanceName, cfg, ctx);
if (locJvmInstance == null && !isRemoteJvm(igniteInstanceName))
locJvmInstance = ignite;
return ignite;
}
use of org.apache.ignite.testframework.junits.multijvm.IgniteProcessProxy in project ignite by apache.
the class GridAbstractTest method executeRemotely.
/**
* Calls job on remote JVM.
*
* @param idx Grid index.
* @param job Job.
*/
public <R> R executeRemotely(final int idx, final TestIgniteIdxCallable<R> job) {
IgniteEx ignite = grid(idx);
if (!isMultiJvmObject(ignite))
throw new IllegalArgumentException("Ignite have to be process proxy.");
IgniteProcessProxy proxy = (IgniteProcessProxy) ignite;
return proxy.remoteCompute().call(new ExecuteRemotelyTask<>(job, idx));
}
use of org.apache.ignite.testframework.junits.multijvm.IgniteProcessProxy in project ignite by apache.
the class GridAbstractTest method executeRemotely.
/**
* Runs job on remote JVM.
*
* @param cache Cache.
* @param job Job.
*/
public static <K, V, R> R executeRemotely(IgniteCacheProcessProxy<K, V> cache, final TestCacheCallable<K, V, R> job) {
IgniteProcessProxy proxy = (IgniteProcessProxy) cache.unwrap(Ignite.class);
final UUID id = proxy.getId();
final String cacheName = cache.getName();
return proxy.remoteCompute().call(new IgniteCallable<R>() {
private static final long serialVersionUID = -3868429485920845137L;
@Override
public R call() throws Exception {
Ignite ignite = Ignition.ignite(id);
IgniteCache<K, V> cache = ignite.cache(cacheName);
return job.call(ignite, cache);
}
});
}
Aggregations