Search in sources :

Example 1 with ListenedGridTestLog4jLogger

use of org.apache.ignite.compatibility.testframework.junits.logger.ListenedGridTestLog4jLogger 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)

Aggregations

URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 UUID (java.util.UUID)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 IgniteLogger (org.apache.ignite.IgniteLogger)1 ListenedGridTestLog4jLogger (org.apache.ignite.compatibility.testframework.junits.logger.ListenedGridTestLog4jLogger)1 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)1 IgniteProcessProxy (org.apache.ignite.testframework.junits.multijvm.IgniteProcessProxy)1