# ignite-117 : refactoring (java-doc and etc.)
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/d01fa229 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/d01fa229 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/d01fa229 Branch: refs/heads/sprint-1 Commit: d01fa229ea9552e9e5b7272dea89266a63fac3ed Parents: d5ef125 Author: Artem SHutak <ashu...@gridgain.com> Authored: Wed Jan 28 21:30:00 2015 +0300 Committer: Artem SHutak <ashu...@gridgain.com> Committed: Wed Jan 28 21:30:00 2015 +0300 ---------------------------------------------------------------------- .../apache/ignite/internal/util/GridUtils.java | 22 +++++++----- .../ipc/shmem/IpcSharedMemoryNativeLoader.java | 10 +++--- .../IpcSharedMemoryNativeLoaderSelfTest.java | 32 ++++++++++++++++++ .../LoadWithCorruptedLibFileTestRunner.java | 35 ++++++++++++++++++-- 4 files changed, 83 insertions(+), 16 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d01fa229/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 62b2069..9f01e98 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 @@ -9099,12 +9099,14 @@ public abstract class GridUtils { } /** - * @param in - * @return - * @throws NoSuchAlgorithmException - * @throws IOException + * Calculate MD5 digits. + * + * @param in Input stream. + * @return Calculated MD5 digest for given input stream. + * @throws NoSuchAlgorithmException If MD5 algorithm was not found. + * @throws IOException If an I/O exception occurs. */ - public static byte[] calculateMD5Digest(InputStream in) throws NoSuchAlgorithmException, IOException { + public static byte[] calculateMD5Digest(@NotNull InputStream in) throws NoSuchAlgorithmException, IOException { MessageDigest md = MessageDigest.getInstance("MD5"); InputStream fis = new BufferedInputStream(in); byte[] dataBytes = new byte[1024]; @@ -9118,10 +9120,12 @@ public abstract class GridUtils { } /** - * @param in Input. - * @return - * @throws NoSuchAlgorithmException - * @throws IOException + * Calculate MD5 string. + * + * @param in Input stream. + * @return Calculated MD5 string for given input stream. + * @throws NoSuchAlgorithmException If MD5 algorithm was not found. + * @throws IOException If an I/O exception occurs. */ public static String calculateMD5(InputStream in) throws NoSuchAlgorithmException, IOException { byte[] md5Bytes = calculateMD5Digest(in); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d01fa229/modules/core/src/main/java/org/apache/ignite/internal/util/ipc/shmem/IpcSharedMemoryNativeLoader.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/ipc/shmem/IpcSharedMemoryNativeLoader.java b/modules/core/src/main/java/org/apache/ignite/internal/util/ipc/shmem/IpcSharedMemoryNativeLoader.java index a835c96..cb52912 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/ipc/shmem/IpcSharedMemoryNativeLoader.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/ipc/shmem/IpcSharedMemoryNativeLoader.java @@ -242,11 +242,11 @@ public class IpcSharedMemoryNativeLoader { } /** - * @param target - * @param src - * @return - * @throws NoSuchAlgorithmException - * @throws IOException + * @param target Target. + * @param src Source. + * @return {@code True} if target md5-sum equal to source md5-sum. + * @throws NoSuchAlgorithmException If md5 algorithm was not found. + * @throws IOException If an I/O exception occurs. */ private static boolean haveEqualMD5(File target, URL src) throws NoSuchAlgorithmException, IOException { try (InputStream targetIS = new FileInputStream(target); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d01fa229/modules/core/src/test/java/org/apache/ignite/internal/util/ipc/shmem/IpcSharedMemoryNativeLoaderSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/util/ipc/shmem/IpcSharedMemoryNativeLoaderSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/util/ipc/shmem/IpcSharedMemoryNativeLoaderSelfTest.java index e75eb04..e70c207 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/util/ipc/shmem/IpcSharedMemoryNativeLoaderSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/util/ipc/shmem/IpcSharedMemoryNativeLoaderSelfTest.java @@ -1,3 +1,20 @@ +/* + * 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. + */ + package org.apache.ignite.internal.util.ipc.shmem; import junit.framework.*; @@ -7,8 +24,17 @@ import org.apache.ignite.internal.util.typedef.internal.*; import java.io.*; import java.util.*; +/** + * Test shared memory native loader. + */ public class IpcSharedMemoryNativeLoaderSelfTest extends TestCase { + /** + * Test {@link IpcSharedMemoryNativeLoader#load()} in case, when native library path was + * already loaded, but corrupted. + * + * @throws Exception If failed. + */ public void testLoadWithCorruptedLibFile() throws Exception { if (U.isWindows()) return; @@ -30,6 +56,12 @@ public class IpcSharedMemoryNativeLoaderSelfTest extends TestCase { assertEquals("Returned code have to be 0.", 0, code); } + /** + * Read information from process streams. + * + * @param proc Process. + * @throws IOException If an I/O error occurs. + */ private void readStreams(Process proc) throws IOException { BufferedReader stdOut = new BufferedReader(new InputStreamReader(proc.getInputStream())); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d01fa229/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 a3b4a0e..e365710 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 @@ -1,13 +1,39 @@ +/* + * 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. + */ + package org.apache.ignite.internal.util.ipc.shmem; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; +/** + * Helper class for {@link IpcSharedMemoryNativeLoaderSelfTest#testLoadWithCorruptedLibFile()} test, which contains test logic. + */ 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(IpcSharedMemoryNativeLoader.LIB_NAME); + /** + * Do logic of test. + * + * @param args Args. + * @throws Exception If test failed. + */ public static void main(String[] args) throws Exception { System.setProperty("java.io.tmpdir", TMP_DIR_FOR_TEST); @@ -16,15 +42,20 @@ public class LoadWithCorruptedLibFileTestRunner { IpcSharedMemoryNativeLoader.load(); } + /** + * Create corrupted library file. + * + * @throws IOException If an I/O error occurs. + */ private static void createCorruptedLibFile() throws IOException { File libFile = new File(System.getProperty("java.io.tmpdir"), LOADED_LIB_FILE_NAME); - if (libFile.exists() && ! libFile.delete()) + if (libFile.exists() && !libFile.delete()) throw new IllegalStateException("Could not delete loaded lib file."); libFile.deleteOnExit(); - if (! libFile.createNewFile()) + if (!libFile.createNewFile()) throw new IllegalStateException("Could not create new file."); try (FileOutputStream out = new FileOutputStream(libFile)) {