ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [2/5] incubator-ignite git commit: #nodejs: move all nodejs files to ignite-nodejs module.
Date Fri, 05 Jun 2015 14:19:38 GMT
#nodejs: move all nodejs files to ignite-nodejs module.


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/6546a873
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/6546a873
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/6546a873

Branch: refs/heads/nodejs
Commit: 6546a8732ac763abc9d778481f52b0ca6675eba6
Parents: de9f02a
Author: ivasilinets <ivasilinets@gridgain.com>
Authored: Fri Jun 5 15:58:03 2015 +0300
Committer: ivasilinets <ivasilinets@gridgain.com>
Committed: Fri Jun 5 15:58:03 2015 +0300

----------------------------------------------------------------------
 modules/nodejs/pom.xml                          |   6 +
 modules/nodejs/src/main/nodejs/cache.js         |  56 +++++++
 modules/nodejs/src/main/nodejs/ignition.js      |  49 ++++++
 modules/nodejs/src/main/nodejs/server.js        |  94 +++++++++++
 .../apache/ignite/internal/NodeJsSelfTest.java  | 118 +++++++++++++
 modules/nodejs/src/test/nodejs/rest-jetty.xml   |  53 ++++++
 modules/nodejs/src/test/nodejs/runtest.bat      |  17 ++
 modules/nodejs/src/test/nodejs/runtest.sh       |   6 +
 modules/nodejs/src/test/nodejs/test-node.xml    |  97 +++++++++++
 modules/nodejs/src/test/nodejs/test.js          | 166 +++++++++++++++++++
 10 files changed, 662 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6546a873/modules/nodejs/pom.xml
----------------------------------------------------------------------
diff --git a/modules/nodejs/pom.xml b/modules/nodejs/pom.xml
index f4ee60a..5dbfc89 100644
--- a/modules/nodejs/pom.xml
+++ b/modules/nodejs/pom.xml
@@ -48,6 +48,12 @@
 
         <dependency>
             <groupId>org.apache.ignite</groupId>
+            <artifactId>ignite-log4j</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.ignite</groupId>
             <artifactId>ignite-rest-http</artifactId>
             <version>${project.version}</version>
         </dependency>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6546a873/modules/nodejs/src/main/nodejs/cache.js
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/main/nodejs/cache.js b/modules/nodejs/src/main/nodejs/cache.js
new file mode 100644
index 0000000..59c8ece
--- /dev/null
+++ b/modules/nodejs/src/main/nodejs/cache.js
@@ -0,0 +1,56 @@
+/**
+ * Creates an instance of Cache
+ *
+ * @constructor
+ * @this {Cache}
+ * @param {Server} server Server class
+ * @param {string} cacheName Cache name
+ */
+function Cache(server, cacheName) {
+    this._server = server;
+    this._cacheName = cacheName;
+    this._cacheNameParam = _pair("cacheName", this._cacheName);
+}
+
+/**
+ * Get cache value
+ *
+ * @this {Cache}
+ * @param {string} key Key
+ * @param {Cache~onGet} callback Called on finish
+ */
+Cache.prototype.get = function(key, callback) {
+    this._server.runCommand("get", [this._cacheNameParam, _pair("key", key)], callback);
+};
+
+/**
+ * Callback for cache get
+ * @callback Cache~onGet
+ * @param {string} error Error
+ * @param {string} result Result value
+ */
+
+/**
+ * Put cache value
+ *
+ * @this {Cache}
+ * @param {string} key Key
+ * @param {string} value Value
+ * @param {Cache~onPut} callback Called on finish
+ */
+Cache.prototype.put = function(key, value, callback) {
+    this._server.runCommand("put", [this._cacheNameParam, _pair("key", key), _pair("val",
value)],
+        callback);
+}
+
+/**
+ * Callback for cache put
+ * @callback Cache~onPut
+ * @param {string} error Error
+ */
+
+function _pair(key, value) {
+    return {key: key, value: value}
+}
+
+exports.Cache = Cache
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6546a873/modules/nodejs/src/main/nodejs/ignition.js
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/main/nodejs/ignition.js b/modules/nodejs/src/main/nodejs/ignition.js
new file mode 100644
index 0000000..1d8aa46
--- /dev/null
+++ b/modules/nodejs/src/main/nodejs/ignition.js
@@ -0,0 +1,49 @@
+/**
+ * Creates an instance of Ignition
+ *
+ * @constructor
+ */
+function Ignition() {
+}
+
+/**
+ * Callback for Ignition start
+ *
+ * @callback Ignition~onStart
+ * @param {string} error Error
+ * @param {Server} server Connected server
+ */
+
+/**
+ * Open connection with server node
+ *
+ * @param {number} port Port
+ * @param {string[]} hosts List of nodes hosts
+ * @param {Ignition~onStart} callback Called on finish
+ */
+Ignition.start = function(port, hosts, callback) {
+    var Server = require("./server").Server;
+    var numConn = hosts.length;
+    for (var host of hosts) {
+        var server = new Server(host, port);
+        server.checkConnection(onConnect.bind(null, server));
+    }
+
+    function onConnect(server, error) {
+        if (!callback)
+            return;
+
+        numConn--;
+        if (!error) {
+            callback.call(null, null, server);
+            callback = null;
+            return;
+        }
+
+        console.log(error);
+        if (!numConn)
+            callback.call(null, "Cannot connect to servers", null);
+    }
+}
+
+exports.Ignition = Ignition;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6546a873/modules/nodejs/src/main/nodejs/server.js
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/main/nodejs/server.js b/modules/nodejs/src/main/nodejs/server.js
new file mode 100644
index 0000000..fa6d477
--- /dev/null
+++ b/modules/nodejs/src/main/nodejs/server.js
@@ -0,0 +1,94 @@
+/**
+ * Creates an instance of Server
+ *
+ * @constructor
+ * @this {Server}
+ * @param {string} host Host address
+ * @param {number} port Port
+ */
+function Server(host, port) {
+    this._host = host;
+    this._port = port;
+}
+
+/**
+ * Host value
+ *
+ * @this {Server}
+ * @returns {string} Host value
+ */
+Server.prototype.host = function()
+{
+    return this._host;
+}
+
+/**
+ * Callback for Server runCommand
+ *
+ * @callback Server~onRunCommand
+ * @param {string} error Error
+ * @param {string} result Result value
+ */
+
+/**
+ * Run http request
+ *
+ * @this {Server}
+ * @param {string} cmdName command name.
+ * @param params Parameters for command.
+ * @param {Server~onRunCommand} Called on finish
+ */
+Server.prototype.runCommand = function(cmdName, params, callback) {
+    var paramsString = "";
+
+    for (var p of params)
+        //TODO: escape value
+        paramsString += "&" + p.key + "=" + p.value;
+
+    var requestQry = "cmd=" + cmdName + paramsString;
+
+    var http = require('http');
+
+    var options = {
+        host: this._host,
+        port: this._port,
+        path: "/ignite?" + requestQry
+    };
+
+    function streamCallback(response) {
+        var fullResponseString = '';
+
+        response.on('data', function (chunk) {
+            fullResponseString += chunk;
+        });
+
+        response.on('end', function () {
+            try {
+                var response = JSON.parse(fullResponseString);
+                if (response.successStatus)
+                    callback.call(null, response.error, null)
+                else
+                    callback.call(null, null, response.response);
+            } catch (e) {
+                callback.call(null, e, null);
+            }
+        });
+    }
+
+    var request = http.request(options, streamCallback);
+
+    request.on('error', callback);
+    request.end();
+}
+
+/**
+ * Check the connection with server node.
+ *
+ * @this {Server}
+ * @param {Server~onRunCommand} callback Called on finish
+ */
+Server.prototype.checkConnection = function(callback) {
+    this.runCommand("version", [], callback);
+}
+
+exports.Server = Server;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6546a873/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsSelfTest.java b/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsSelfTest.java
new file mode 100644
index 0000000..d79dc76
--- /dev/null
+++ b/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsSelfTest.java
@@ -0,0 +1,118 @@
+/*
+ *  Copyright (C) GridGain Systems. All Rights Reserved.
+ *  _________        _____ __________________        _____
+ *  __  ____/___________(_)______  /__  ____/______ ____(_)_______
+ *  _  / __  __  ___/__  / _  __  / _  / __  _  __ `/__  / __  __ \
+ *  / /_/ /  _  /    _  /  / /_/ /  / /_/ /  / /_/ / _  /  _  / / /
+ *  \____/   /_/     /_/   \_,__/   \____/   \__,_/  /_/   /_/ /_/
+ */
+
+package org.apache.ignite.internal;
+
+import org.apache.ignite.cache.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.internal.util.*;
+import org.apache.ignite.internal.util.typedef.*;
+import org.apache.ignite.internal.util.typedef.internal.*;
+import org.apache.ignite.testframework.junits.common.*;
+
+import java.util.*;
+import java.util.concurrent.*;
+
+import static java.util.concurrent.TimeUnit.*;
+
+/**
+ * Test node js client.
+ */
+public class NodeJsSelfTest extends GridCommonAbstractTest {
+    /** Cache name. */
+    private static final String CACHE_NAME = "mycache";
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception
{
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+        cfg.setCacheConfiguration(cacheConfiguration());
+
+        ConnectorConfiguration conCfg = new ConnectorConfiguration();
+
+        conCfg.setJettyPath(getNodeJsTestDir() + "rest-jetty.xml");
+
+        cfg.setConnectorConfiguration(conCfg);
+
+        return cfg;
+    }
+
+    /**
+     * @return Cache configuration.
+     */
+    private CacheConfiguration cacheConfiguration() {
+        CacheConfiguration ccfg = new CacheConfiguration();
+
+        ccfg.setName(CACHE_NAME);
+        ccfg.setAtomicityMode(CacheAtomicityMode.ATOMIC);
+
+        return ccfg;
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPutGetJs() throws Exception {
+        startGrid(0);
+
+        final CountDownLatch readyLatch = new CountDownLatch(1);
+
+        GridJavaProcess proc = null;
+
+        final List<String> errors = new ArrayList<>();
+
+        try {
+            proc = GridJavaProcess.exec(
+                getNodeJsTestDir() + "runtest.bat",
+                log,
+                new CI1<String>() {
+                    @Override
+                    public void apply(String s) {
+                        info("Node js: " + s);
+
+                        if (s.contains("OK: "))
+                            readyLatch.countDown();
+
+                        if (s.contains("Error") || s.contains("FAILURES")) {
+                            errors.add("Script failed: " + s);
+
+                            readyLatch.countDown();
+                        }
+                    }
+                },
+                null
+            );
+
+            assertTrue(readyLatch.await(60, SECONDS));
+
+            assertEquals(errors.toString(), 0, errors.size());
+
+            proc.getProcess().waitFor();
+        }
+        finally {
+            stopAllGrids();
+
+            if (proc != null)
+                proc.killProcess();
+        }
+    }
+
+    /**
+     * @return Node js test dir.
+     */
+    private String getNodeJsTestDir() {
+        String sep = System.getProperty("file.separator");
+
+        return U.getIgniteHome() +
+            sep + "modules" +
+            sep + "nodejs" +
+            sep + "src" +
+            sep + "test" +
+            sep + "nodejs" + sep;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6546a873/modules/nodejs/src/test/nodejs/rest-jetty.xml
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/test/nodejs/rest-jetty.xml b/modules/nodejs/src/test/nodejs/rest-jetty.xml
new file mode 100644
index 0000000..e31304f
--- /dev/null
+++ b/modules/nodejs/src/test/nodejs/rest-jetty.xml
@@ -0,0 +1,53 @@
+<?xml version="1.0"?>
+<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
+<Configure id="Server" class="org.eclipse.jetty.server.Server">
+    <Arg name="threadPool">
+        <!-- Default queued blocking thread pool -->
+        <New class="org.eclipse.jetty.util.thread.QueuedThreadPool">
+            <Set name="minThreads">20</Set>
+            <Set name="maxThreads">200</Set>
+        </New>
+    </Arg>
+    <New id="httpCfg" class="org.eclipse.jetty.server.HttpConfiguration">
+        <Set name="secureScheme">https</Set>
+        <Set name="securePort">8443</Set>
+        <Set name="sendServerVersion">true</Set>
+        <Set name="sendDateHeader">true</Set>
+    </New>
+    <Call name="addConnector">
+        <Arg>
+            <New class="org.eclipse.jetty.server.ServerConnector">
+                <Arg name="server"><Ref refid="Server"/></Arg>
+                <Arg name="factories">
+                    <Array type="org.eclipse.jetty.server.ConnectionFactory">
+                        <Item>
+                            <New class="org.eclipse.jetty.server.HttpConnectionFactory">
+                                <Ref refid="httpCfg"/>
+                            </New>
+                        </Item>
+                    </Array>
+                </Arg>
+                <Set name="host">
+                    <SystemProperty name="IGNITE_JETTY_HOST" default="localhost"/>
+                </Set>
+                <Set name="port">
+                    <SystemProperty name="IGNITE_JETTY_PORT" default="9090"/>
+                </Set>
+                <Set name="idleTimeout">30000</Set>
+                <Set name="reuseAddress">true</Set>
+            </New>
+        </Arg>
+    </Call>
+    <Set name="handler">
+        <New id="Handlers" class="org.eclipse.jetty.server.handler.HandlerCollection">
+            <Set name="handlers">
+                <Array type="org.eclipse.jetty.server.Handler">
+                    <Item>
+                        <New id="Contexts" class="org.eclipse.jetty.server.handler.ContextHandlerCollection"/>
+                    </Item>
+                </Array>
+            </Set>
+        </New>
+    </Set>
+    <Set name="stopAtShutdown">false</Set>
+</Configure>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6546a873/modules/nodejs/src/test/nodejs/runtest.bat
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/test/nodejs/runtest.bat b/modules/nodejs/src/test/nodejs/runtest.bat
new file mode 100644
index 0000000..c3e0648
--- /dev/null
+++ b/modules/nodejs/src/test/nodejs/runtest.bat
@@ -0,0 +1,17 @@
+::
+:: Copyright (C) GridGain Systems. All Rights Reserved.
+::
+:: _________        _____ __________________        _____
+:: __  ____/___________(_)______  /__  ____/______ ____(_)_______
+:: _  / __  __  ___/__  / _  __  / _  / __  _  __ `/__  / __  __ \
+:: / /_/ /  _  /    _  /  / /_/ /  / /_/ /  / /_/ / _  /  _  / / /
+:: \____/   /_/     /_/   \_,__/   \____/   \__,_/  /_/   /_/ /_/
+::
+::
+
+::
+:: Internal script that starts test runner.
+::
+if "%IGNITE_HOME%" == "" echo %0, ERROR: IGNITE_HOME environment vairable is not found.
+
+nodeunit %IGNITE_HOME%\modules\nodejs\src\test\nodejs\test.js
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6546a873/modules/nodejs/src/test/nodejs/runtest.sh
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/test/nodejs/runtest.sh b/modules/nodejs/src/test/nodejs/runtest.sh
new file mode 100644
index 0000000..a60da47
--- /dev/null
+++ b/modules/nodejs/src/test/nodejs/runtest.sh
@@ -0,0 +1,6 @@
+#!/usr/bin/env bash
+if [ "${IGNITE_HOME}" = "" ]; then
+    export IGNITE_HOME="$(dirname $(readlink -f $0))"/..
+fi
+
+nodeunit ${IGNITE_HOME}$/../ggprivate/modules/clients/src/test/nodejs/test.js
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6546a873/modules/nodejs/src/test/nodejs/test-node.xml
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/test/nodejs/test-node.xml b/modules/nodejs/src/test/nodejs/test-node.xml
new file mode 100644
index 0000000..a1a17e4
--- /dev/null
+++ b/modules/nodejs/src/test/nodejs/test-node.xml
@@ -0,0 +1,97 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  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.
+-->
+
+<!--
+    Ignite configuration with all defaults and enabled p2p deployment and enabled events.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:util="http://www.springframework.org/schema/util"
+       xsi:schemaLocation="
+        http://www.springframework.org/schema/beans
+        http://www.springframework.org/schema/beans/spring-beans.xsd
+        http://www.springframework.org/schema/util
+        http://www.springframework.org/schema/util/spring-util.xsd">
+    <bean id="ignite.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
+        <!-- Set to true to enable distributed class loading for examples, default is
false. -->
+        <property name="peerClassLoadingEnabled" value="true"/>
+
+        <property name="cacheConfiguration">
+            <list>
+                <!-- Partitioned cache example configuration (Atomic mode). -->
+                <bean class="org.apache.ignite.configuration.CacheConfiguration">
+                    <property name="name" value="mycache"/>
+                    <property name="atomicityMode" value="ATOMIC"/>
+                    <property name="backups" value="1"/>
+                </bean>
+            </list>
+        </property>
+
+        <property name="marshaller">
+            <bean class="org.apache.ignite.marshaller.optimized.OptimizedMarshaller">
+                <!-- Set to false to allow non-serializable objects in examples, default
is true. -->
+                <property name="requireSerializable" value="false"/>
+            </bean>
+        </property>
+
+        <property name="connectorConfiguration">
+            <bean class="org.apache.ignite.configuration.ConnectorConfiguration">
+                <property name="jettyPath" value="rest-jetty.xml"/>
+            </bean>
+        </property>
+
+        <!-- Enable task execution events for examples. -->
+        <property name="includeEventTypes">
+            <list>
+                <!--Task execution events-->
+                <util:constant static-field="org.apache.ignite.events.EventType.EVT_TASK_STARTED"/>
+                <util:constant static-field="org.apache.ignite.events.EventType.EVT_TASK_FINISHED"/>
+                <util:constant static-field="org.apache.ignite.events.EventType.EVT_TASK_FAILED"/>
+                <util:constant static-field="org.apache.ignite.events.EventType.EVT_TASK_TIMEDOUT"/>
+                <util:constant static-field="org.apache.ignite.events.EventType.EVT_TASK_SESSION_ATTR_SET"/>
+                <util:constant static-field="org.apache.ignite.events.EventType.EVT_TASK_REDUCED"/>
+
+                <!--Cache events-->
+                <util:constant static-field="org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_PUT"/>
+                <util:constant static-field="org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_READ"/>
+                <util:constant static-field="org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_REMOVED"/>
+            </list>
+        </property>
+
+        <!-- Explicitly configure TCP discovery SPI to provide list of initial nodes.
-->
+        <property name="discoverySpi">
+            <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
+                <property name="ipFinder">
+                    <!--
+                        Ignite provides several options for automatic discovery that can
be used
+                        instead os static IP based discovery. For information on all options
refer
+                        to our documentation: http://apacheignite.readme.io/docs/cluster-config
+                    -->
+                    <!-- Uncomment static IP finder to enable static-based discovery of
initial nodes. -->
+                    <!--<bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">-->
+                    <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">
+                        <constructor-arg>
+                            <value>true</value>
+                        </constructor-arg>
+                    </bean>
+                </property>
+            </bean>
+        </property>
+    </bean>
+</beans>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6546a873/modules/nodejs/src/test/nodejs/test.js
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/test/nodejs/test.js b/modules/nodejs/src/test/nodejs/test.js
new file mode 100644
index 0000000..39fcafd
--- /dev/null
+++ b/modules/nodejs/src/test/nodejs/test.js
@@ -0,0 +1,166 @@
+module.exports = {
+    'Test put/get' : function(test) {
+        test.expect(1);
+
+        var Cache = require(scriptPath() + "cache").Cache;
+        var Server = require(scriptPath() + "server").Server;
+
+        var assert = require('assert');
+
+        //var node = startIgniteNode();
+
+        setTimeout(initCache, 10000); //If start node from javascrip set timeout 10000);
+
+        function initCache() {
+            var server = new Server('127.0.0.1', 9090);
+            var cache = new Cache(server, "mycache");
+            cache.put("mykey", "6", onPut.bind(null, cache));
+        }
+
+        function onPut(cache, error) {
+            if (error) {
+                console.error("Failed to put " + error);
+                finishTest(test/*, node*/);
+                return;
+            }
+
+            console.log("Put finished");
+            cache.get("mykey", onGet);
+        }
+
+        function onGet(error, value) {
+            if (error) {
+                console.error("Failed to get " + error);
+                finishTest(test/*, node*/);
+                return;
+            }
+
+            console.log("Get finished");
+            test.ok(value === "6", "This shouldn't fail " + value + "<>6");
+            finishTest(test/*, node*/);
+        }
+    },
+    'Test connection' : function(test) {
+        test.expect(0);
+
+        //var node = startIgniteNode();
+
+        var Server = require(scriptPath() + "server").Server;
+
+        setTimeout(initServer, 10000);
+
+        function initServer() {
+            var server = new Server('127.0.0.1', 9090);
+
+            console.log("Try to check connection");
+
+            server.checkConnection(onConnect);
+        }
+
+        function onConnect(error) {
+            if (error) {
+                finishWithError(test/*, node*/, error);
+                return;
+            }
+            console.log("Successfully connected");
+            finishTest(test/*, node*/);
+        }
+    },
+    'Test ignition' : function(test) {
+        test.expect(1);
+
+        //var node = startIgniteNode('127.0.0.1', 9090);
+
+        var Ignition = require(scriptPath() + "ignition").Ignition;
+
+        setTimeout(Ignition.start.bind(null, 9090, ['127.0.0.0', '127.0.0.1'], onConnect),
5000);
+
+        function onConnect(error, server) {
+            if (error) {
+                finishWithError(test/*, node*/, error);
+                return;
+            }
+            test.ok(server.host() === '127.0.0.1')
+            finishTest(test/*, node*/);
+        }
+    }
+ };
+
+function scriptPath() {
+    return igniteHome() +
+       sep() + "modules" +
+       sep() + "nodejs" +
+       sep() + "src" +
+       sep() + "main" +
+       sep() + "nodejs" + sep();
+}
+
+function startIgniteNode() {
+    var libs = classpath(igniteHome() +  sep() + "target" +
+        sep() + "bin" +
+        sep() + "apache-ignite-fabric-1.1.1-SNAPSHOT-bin" +
+        sep() + "libs");
+
+    var cp = libs.join(require('path').delimiter);
+
+    var spawn = require('child_process').spawn;
+
+    var child = spawn('java',['-classpath', cp, 'org.apache.ignite.startup.cmdline.CommandLineStartup',
+        "test-node.xml"]);
+
+    child.stdout.on('data', function (data) {
+        console.log("" + data);
+    });
+
+    child.stderr.on('data', function (data) {
+        console.log("" + data);
+    });
+
+    return child;
+}
+
+function finishWithError(test/*, node*/, error) {
+    console.log("Error: " + error);
+    test.ok(false);
+    finishTest(test/*, node*/);
+}
+
+function finishTest(test/*, node*/) {
+    //node.kill();
+    test.done();
+}
+
+function igniteHome() {
+    return process.env.IGNITE_HOME;
+}
+
+function sep() {
+    return require('path').sep;
+}
+
+function classpath(dir) {
+    var fs = require('fs');
+    var path = require('path');
+    function walk(dir, done) {
+        var results = [];
+        var list = fs.readdirSync(dir)
+        for (var i = 0; i < list.length; ++i) {
+            file = path.resolve(dir, list[i]);
+            var stat = fs.statSync(file);
+            if (stat && stat.isDirectory()) {
+                if (list[i] != "optional" && file.indexOf("optional") !== -1 &&
file.indexOf("rest") == -1 )
+                    continue;
+
+                var sublist = walk(file);
+                results = results.concat(sublist);
+            } else {
+                if (file.indexOf(".jar") !== -1) {
+                    results.push(file);
+                }
+            }
+        }
+        return results;
+    };
+
+    return walk(dir);
+};
\ No newline at end of file


Mime
View raw message