ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [08/45] incubator-ignite git commit: # ignite-117 : run test at own process
Date Thu, 29 Jan 2015 15:32:44 GMT
# ignite-117 : run test at own process


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

Branch: refs/heads/ignite-26
Commit: 3f4c416715b07cdad4b1704a9490b18f05b93b0d
Parents: cd613db
Author: Artem SHutak <ashutak@gridgain.com>
Authored: Tue Jan 27 21:25:24 2015 +0300
Committer: Artem SHutak <ashutak@gridgain.com>
Committed: Tue Jan 27 21:25:24 2015 +0300

----------------------------------------------------------------------
 .../shmem/GridIpcSharedMemoryNativeLoader.java  |  2 -
 ...GridIpcSharedMemoryNativeLoaderSelfTest.java | 41 +++++++++-----------
 .../LoadIfLibFileWasCorruptedTestRunner.java    | 36 +++++++++++++++++
 3 files changed, 54 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3f4c4167/modules/core/src/main/java/org/apache/ignite/internal/util/ipc/shmem/GridIpcSharedMemoryNativeLoader.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/ipc/shmem/GridIpcSharedMemoryNativeLoader.java
b/modules/core/src/main/java/org/apache/ignite/internal/util/ipc/shmem/GridIpcSharedMemoryNativeLoader.java
index 825a235..243a099 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/ipc/shmem/GridIpcSharedMemoryNativeLoader.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/ipc/shmem/GridIpcSharedMemoryNativeLoader.java
@@ -275,8 +275,6 @@ public class GridIpcSharedMemoryNativeLoader {
             sb.append(Integer.toString((md5Byte & 0xff) + 0x100, 16).substring(1));
         }
 
-        System.out.println("Digest(in hex format):: " + sb.toString());
-
         return md5Bytes;
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3f4c4167/modules/core/src/test/java/org/apache/ignite/internal/util/ipc/shmem/GridIpcSharedMemoryNativeLoaderSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/util/ipc/shmem/GridIpcSharedMemoryNativeLoaderSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/util/ipc/shmem/GridIpcSharedMemoryNativeLoaderSelfTest.java
index 196be0a..2d082c2 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/util/ipc/shmem/GridIpcSharedMemoryNativeLoaderSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/util/ipc/shmem/GridIpcSharedMemoryNativeLoaderSelfTest.java
@@ -1,42 +1,37 @@
 package org.apache.ignite.internal.util.ipc.shmem;
 
 import junit.framework.TestCase;
+import org.apache.ignite.internal.util.GridJavaProcess;
 
+import java.io.BufferedReader;
 import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.Collections;
 
 public class GridIpcSharedMemoryNativeLoaderSelfTest extends TestCase {
-    private static final String DEFAULT_TMP_DIR = System.getProperty("java.io.tmpdir");
-    public static final String TMP_DIR_FOR_TEST = System.getProperty("user.home");
-    public static final String LOADED_LIB_FILE_NAME = System.mapLibraryName(GridIpcSharedMemoryNativeLoader.libFileName());
-
     //TODO linux specific
     public void testLoadIfLibFileWasCorrupted() throws Exception {
-        try {
-            System.setProperty("java.io.tmpdir", TMP_DIR_FOR_TEST);
+        Process ps = GridJavaProcess.exec(LoadIfLibFileWasCorruptedTestRunner.class, null,
null, null, null, Collections.<String>emptyList(), null).getProcess();
 
-            createCorruptedLibFile();
+        readStreams(ps);
+        int code = ps.waitFor();
 
-            GridIpcSharedMemoryNativeLoader.load();
-        } finally {
-            System.setProperty("java.io.tmpdir", DEFAULT_TMP_DIR);
-        }
+        assertEquals("Returned code have to be 0.", 0, code);
     }
 
-    private void createCorruptedLibFile() throws IOException {
-        File loadedFile = new File(System.getProperty("java.io.tmpdir"), LOADED_LIB_FILE_NAME);
-
-        if (loadedFile.exists())
-            assertTrue("Could not delete libggshem file.",loadedFile.delete());
-        loadedFile.deleteOnExit();
+    private void readStreams(Process proc) throws IOException {
+        BufferedReader stdOut = new BufferedReader(new InputStreamReader(proc.getInputStream()));
+        String s;
+        while ((s = stdOut.readLine()) != null) {
+            System.out.println("OUT>>>>>> " + s);
+        }
 
-        assertTrue("Could not create new file.", loadedFile.createNewFile());
+        BufferedReader errOut = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
+        while ((s = errOut.readLine()) != null) {
+            System.out.println("ERR>>>>>> " + s);
+        }
 
-        try (FileOutputStream out = new FileOutputStream(loadedFile)){
-            out.write("Corrupted information.\n".getBytes());
-        };
     }
 
     public void testMD5Calculation() throws Exception {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3f4c4167/modules/core/src/test/java/org/apache/ignite/internal/util/ipc/shmem/LoadIfLibFileWasCorruptedTestRunner.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/util/ipc/shmem/LoadIfLibFileWasCorruptedTestRunner.java
b/modules/core/src/test/java/org/apache/ignite/internal/util/ipc/shmem/LoadIfLibFileWasCorruptedTestRunner.java
new file mode 100644
index 0000000..544d2c2
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/util/ipc/shmem/LoadIfLibFileWasCorruptedTestRunner.java
@@ -0,0 +1,36 @@
+package org.apache.ignite.internal.util.ipc.shmem;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+public class LoadIfLibFileWasCorruptedTestRunner {
+    public static final String TMP_DIR_FOR_TEST = System.getProperty("user.home");
+    public static final String LOADED_LIB_FILE_NAME = System.mapLibraryName(GridIpcSharedMemoryNativeLoader.libFileName());
+
+    public static void main(String[] args) throws Exception {
+        System.setProperty("java.io.tmpdir", TMP_DIR_FOR_TEST);
+
+        createCorruptedLibFile();
+
+        GridIpcSharedMemoryNativeLoader.load();
+    }
+
+    private static void createCorruptedLibFile() throws IOException {
+        File libFile = new File(System.getProperty("java.io.tmpdir"), LOADED_LIB_FILE_NAME);
+
+        if (libFile.exists() && ! libFile.delete())
+            throw new IllegalStateException("Could not delete loaded lib file.");
+
+        libFile.deleteOnExit();
+
+        if (! libFile.createNewFile())
+            throw new IllegalStateException("Could not create new file.");
+
+        try (FileOutputStream out = new FileOutputStream(libFile)) {
+            out.write("Corrupted file information instead of good info.\n".getBytes());
+        }
+    }
+
+
+}


Mime
View raw message