Search in sources :

Example 6 with IgniteProcessProxy

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;
}
Also used : ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) ListenedGridTestLog4jLogger(org.apache.ignite.compatibility.testframework.junits.logger.ListenedGridTestLog4jLogger) URL(java.net.URL) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgniteLogger(org.apache.ignite.IgniteLogger) UUID(java.util.UUID) IgniteProcessProxy(org.apache.ignite.testframework.junits.multijvm.IgniteProcessProxy)

Example 7 with IgniteProcessProxy

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;
    }
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) UUID(java.util.UUID) IgniteProcessProxy(org.apache.ignite.testframework.junits.multijvm.IgniteProcessProxy)

Example 8 with IgniteProcessProxy

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;
}
Also used : Ignite(org.apache.ignite.Ignite) UUID(java.util.UUID) IgniteProcessProxy(org.apache.ignite.testframework.junits.multijvm.IgniteProcessProxy)

Example 9 with IgniteProcessProxy

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));
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) IgniteProcessProxy(org.apache.ignite.testframework.junits.multijvm.IgniteProcessProxy)

Example 10 with IgniteProcessProxy

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);
        }
    });
}
Also used : BINARY_MARSHALLER_USE_SIMPLE_NAME_MAPPER(org.apache.ignite.testframework.config.GridTestProperties.BINARY_MARSHALLER_USE_SIMPLE_NAME_MAPPER) IgniteCache(org.apache.ignite.IgniteCache) Ignite(org.apache.ignite.Ignite) UUID(java.util.UUID) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) BeansException(org.springframework.beans.BeansException) ObjectStreamException(java.io.ObjectStreamException) TimeoutException(java.util.concurrent.TimeoutException) IgniteException(org.apache.ignite.IgniteException) MalformedURLException(java.net.MalformedURLException) IgniteProcessProxy(org.apache.ignite.testframework.junits.multijvm.IgniteProcessProxy)

Aggregations

IgniteProcessProxy (org.apache.ignite.testframework.junits.multijvm.IgniteProcessProxy)10 IgniteEx (org.apache.ignite.internal.IgniteEx)7 UUID (java.util.UUID)4 Ignite (org.apache.ignite.Ignite)3 ArrayList (java.util.ArrayList)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 IgniteCompute (org.apache.ignite.IgniteCompute)2 PA (org.apache.ignite.internal.util.typedef.PA)2 ObjectStreamException (java.io.ObjectStreamException)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 List (java.util.List)1 Callable (java.util.concurrent.Callable)1 CyclicBarrier (java.util.concurrent.CyclicBarrier)1 TimeoutException (java.util.concurrent.TimeoutException)1 IgniteCache (org.apache.ignite.IgniteCache)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteException (org.apache.ignite.IgniteException)1 IgniteLogger (org.apache.ignite.IgniteLogger)1 SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)1