ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [14/31] incubator-ignite git commit: ignite-117 review
Date Thu, 29 Jan 2015 13:37:07 GMT
ignite-117 review


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

Branch: refs/heads/sprint-1
Commit: c351a7bc6e000bdd88b5a0a701625158ac20dada
Parents: f0db0cc
Author: Yakov Zhdanov <yzhdanov@gridgain.com>
Authored: Wed Jan 28 17:13:29 2015 +0300
Committer: Yakov Zhdanov <yzhdanov@gridgain.com>
Committed: Wed Jan 28 17:13:29 2015 +0300

----------------------------------------------------------------------
 .../apache/ignite/internal/util/GridUtils.java  | 43 +++++++++++---------
 .../shmem/GridIpcSharedMemoryNativeLoader.java  | 37 +++++++++--------
 ...GridIpcSharedMemoryNativeLoaderSelfTest.java | 38 ++++++++++-------
 .../LoadWithCorruptedLibFileTestRunner.java     |  4 +-
 4 files changed, 68 insertions(+), 54 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c351a7bc/modules/core/src/main/java/org/apache/ignite/internal/util/GridUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/GridUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/util/GridUtils.java
index d46e5cf..62b2069 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/GridUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/GridUtils.java
@@ -8621,7 +8621,7 @@ public abstract class GridUtils {
 
         byte[] out = new byte[len >> 1];
 
-        // two characters form the hex value.
+        // Two characters form the hex value.
         for (int i = 0, j = 0; j < len; i++) {
             int f = toDigit(data[j], j) << 4;
 
@@ -9098,37 +9098,40 @@ public abstract class GridUtils {
         return list;
     }
 
-    public static byte[] calculateMD5Digest(InputStream input) throws NoSuchAlgorithmException,
IOException {
+    /**
+     * @param in
+     * @return
+     * @throws NoSuchAlgorithmException
+     * @throws IOException
+     */
+    public static byte[] calculateMD5Digest(InputStream in) throws NoSuchAlgorithmException,
IOException {
         MessageDigest md = MessageDigest.getInstance("MD5");
-        InputStream fis = new BufferedInputStream(input);
+        InputStream fis = new BufferedInputStream(in);
         byte[] dataBytes = new byte[1024];
 
         int nread;
-        while ((nread = fis.read(dataBytes)) != -1) {
-            md.update(dataBytes, 0, nread);
-        }
 
-        byte[] md5Bytes = md.digest();
-
-        //convert the byte to hex format
-        StringBuilder sb = new StringBuilder("");
-        for (byte md5Byte : md5Bytes) {
-            sb.append(Integer.toString((md5Byte & 0xff) + 0x100, 16).substring(1));
-        }
+        while ((nread = fis.read(dataBytes)) != -1)
+            md.update(dataBytes, 0, nread);
 
-        return md5Bytes;
+        return md.digest();
     }
 
-    public static String calculateMD5(InputStream input) throws NoSuchAlgorithmException,
IOException {
-        byte[] md5Bytes = calculateMD5Digest(input);
+    /**
+     * @param in Input.
+     * @return
+     * @throws NoSuchAlgorithmException
+     * @throws IOException
+     */
+    public static String calculateMD5(InputStream in) throws NoSuchAlgorithmException, IOException
{
+        byte[] md5Bytes = calculateMD5Digest(in);
 
-        //convert the byte to hex format
+        // Convert the byte to hex format.
         StringBuilder sb = new StringBuilder();
-        for (byte md5Byte : md5Bytes) {
+
+        for (byte md5Byte : md5Bytes)
             sb.append(Integer.toString((md5Byte & 0xff) + 0x100, 16).substring(1));
-        }
 
         return sb.toString();
     }
-
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c351a7bc/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 36d056c..ef310ec 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
@@ -17,16 +17,15 @@
 
 package org.apache.ignite.internal.util.ipc.shmem;
 
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.internal.GridProductImpl;
-import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.*;
+import org.apache.ignite.internal.*;
+import org.apache.ignite.internal.util.typedef.internal.*;
 
 import java.io.*;
-import java.net.URL;
-import java.nio.channels.FileLock;
-import java.security.NoSuchAlgorithmException;
-import java.util.Collection;
-import java.util.LinkedList;
+import java.net.*;
+import java.nio.channels.*;
+import java.security.*;
+import java.util.*;
 
 /**
  * Shared memory native loader.
@@ -39,12 +38,12 @@ public class GridIpcSharedMemoryNativeLoader {
     /** Library name base. */
     private static final String LIB_NAME_BASE = "ggshmem";
 
-    /** Library name. */
-    private static final String LIB_NAME = LIB_NAME_BASE + "-" + GridProductImpl.VER;
-
     /** Lock file path. */
     private static final File LOCK_FILE = new File(System.getProperty("java.io.tmpdir"),
"ggshmem.lock");
 
+    /** Library name. */
+    static final String LIB_NAME = LIB_NAME_BASE + "-" + GridProductImpl.VER;
+
     /**
      * @return Operating system name to resolve path to library.
      */
@@ -63,8 +62,6 @@ public class GridIpcSharedMemoryNativeLoader {
         return name.replaceAll("\\W+", "_");
     }
 
-    static String libFileName(){return LIB_NAME;}
-
     /**
      * @return Platform.
      */
@@ -111,7 +108,7 @@ public class GridIpcSharedMemoryNativeLoader {
     private static void doLoad() throws IgniteCheckedException {
         assert Thread.holdsLock(GridIpcSharedMemoryNativeLoader.class);
 
-        Collection<Throwable> errs = new LinkedList<>();
+        Collection<Throwable> errs = new ArrayList<>();
 
         try {
             // Load native library (the library directory should be in java.library.path).
@@ -210,7 +207,7 @@ public class GridIpcSharedMemoryNativeLoader {
         InputStream is = null;
 
         try {
-            if (!target.exists() || ! haveEqualMD5(target, src)) {
+            if (!target.exists() || !haveEqualMD5(target, src)) {
                 is = src.openStream();
 
                 if (is != null) {
@@ -244,9 +241,16 @@ public class GridIpcSharedMemoryNativeLoader {
         return false;
     }
 
+    /**
+     * @param target
+     * @param src
+     * @return
+     * @throws NoSuchAlgorithmException
+     * @throws IOException
+     */
     private static boolean haveEqualMD5(File target, URL src) throws NoSuchAlgorithmException,
IOException {
         try (InputStream targetIS = new FileInputStream(target);
-             InputStream srcIS = src.openStream()){
+             InputStream srcIS = src.openStream()) {
 
             String targetMD5 = U.calculateMD5(targetIS);
             String srcMD5 = U.calculateMD5(srcIS);
@@ -254,5 +258,4 @@ public class GridIpcSharedMemoryNativeLoader {
             return targetMD5.equals(srcMD5);
         }
     }
-
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c351a7bc/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 96ae3c5..fad783f 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,21 +1,30 @@
 package org.apache.ignite.internal.util.ipc.shmem;
 
-import junit.framework.TestCase;
-import org.apache.ignite.internal.util.GridJavaProcess;
+import junit.framework.*;
+import org.apache.ignite.internal.util.*;
+import org.apache.ignite.internal.util.typedef.internal.*;
 
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.util.Collections;
+import java.io.*;
+import java.util.*;
 
 public class GridIpcSharedMemoryNativeLoaderSelfTest extends TestCase {
 
     public void testLoadWithCorruptedLibFile() throws Exception {
-        if (System.getProperty("os.name").toLowerCase().trim().startsWith("win")) return;
-
-        Process ps = GridJavaProcess.exec(LoadWithCorruptedLibFileTestRunner.class, null,
null, null, null, Collections.<String>emptyList(), null).getProcess();
+        if (U.isWindows())
+            return;
+
+        Process ps = GridJavaProcess.exec(
+            LoadWithCorruptedLibFileTestRunner.class,
+            null,
+            null,
+            null,
+            null,
+            Collections.<String>emptyList(),
+            null
+        ).getProcess();
 
         readStreams(ps);
+
         int code = ps.waitFor();
 
         assertEquals("Returned code have to be 0.", 0, code);
@@ -23,14 +32,15 @@ public class GridIpcSharedMemoryNativeLoaderSelfTest extends TestCase
{
 
     private void readStreams(Process proc) throws IOException {
         BufferedReader stdOut = new BufferedReader(new InputStreamReader(proc.getInputStream()));
+
         String s;
-        while ((s = stdOut.readLine()) != null) {
+
+        while ((s = stdOut.readLine()) != null)
             System.out.println("OUT>>>>>> " + s);
-        }
 
         BufferedReader errOut = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
-        while ((s = errOut.readLine()) != null) {
+
+        while ((s = errOut.readLine()) != null)
             System.out.println("ERR>>>>>> " + s);
-        }
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c351a7bc/modules/core/src/test/java/org/apache/ignite/internal/util/ipc/shmem/LoadWithCorruptedLibFileTestRunner.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/util/ipc/shmem/LoadWithCorruptedLibFileTestRunner.java
b/modules/core/src/test/java/org/apache/ignite/internal/util/ipc/shmem/LoadWithCorruptedLibFileTestRunner.java
index eec6b76..acee749 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/util/ipc/shmem/LoadWithCorruptedLibFileTestRunner.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/util/ipc/shmem/LoadWithCorruptedLibFileTestRunner.java
@@ -6,7 +6,7 @@ import java.io.IOException;
 
 public class LoadWithCorruptedLibFileTestRunner {
     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 final String LOADED_LIB_FILE_NAME = System.mapLibraryName(GridIpcSharedMemoryNativeLoader.LIB_NAME);
 
     public static void main(String[] args) throws Exception {
         System.setProperty("java.io.tmpdir", TMP_DIR_FOR_TEST);
@@ -31,6 +31,4 @@ public class LoadWithCorruptedLibFileTestRunner {
             out.write("Corrupted file information instead of good info.\n".getBytes());
         }
     }
-
-
 }


Mime
View raw message