http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/50f31e6e/modules/core/src/main/java/org/apache/ignite/internal/util/ipc/shmem/GridIpcSharedMemoryUtils.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/ipc/shmem/GridIpcSharedMemoryUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/util/ipc/shmem/GridIpcSharedMemoryUtils.java deleted file mode 100644 index 37a7c38..0000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/ipc/shmem/GridIpcSharedMemoryUtils.java +++ /dev/null @@ -1,242 +0,0 @@ -/* - * 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 org.apache.ignite.*; -import org.apache.ignite.internal.util.typedef.internal.*; - -import java.io.*; -import java.lang.management.*; -import java.nio.*; -import java.util.*; - -/** - * NOTE: Native library should be loaded, before methods of this class are called. Native library is loaded with: {@link - * GridIpcSharedMemoryNativeLoader#load()}. - */ -public class GridIpcSharedMemoryUtils { - /** - * Allocates shared memory segment and semaphores for IPC exchange. - * - * @param tokFileName OS token file name. - * @param size Memory space size in bytes. - * @param debug {@code True} to output debug to stdout (will set global flag). - * @return Shared memory pointer. - * @throws IgniteCheckedException If failed. - */ - static native long allocateSystemResources(String tokFileName, int size, boolean debug) - throws IgniteCheckedException; - - /** - * Attaches to previously allocated shared memory segment. - * - * @param shmemId OS shared memory segment ID. - * @param debug {@code True} to output debug to stdout (will set global flag). - * @return Shared memory pointer. - * @throws IgniteCheckedException If failed. - */ - static native long attach(int shmemId, boolean debug) throws IgniteCheckedException; - - /** - * Stops IPC communication. Call {@link #freeSystemResources(String, long, boolean)} after this call. - * - * @param shmemPtr Shared memory pointer. - */ - static native void ipcClose(long shmemPtr); - - /** - * Frees system resources. - * - * @param tokFileName Token file name. - * @param shmemPtr Shared memory pointer - * @param force {@code True} to force close. - */ - static native void freeSystemResources(String tokFileName, long shmemPtr, boolean force); - - /** - * Frees system resources. - * - * @param tokFileName Token file name. - * @param size Size. - */ - static native void freeSystemResources(String tokFileName, int size); - - /** - * @param shMemPtr Shared memory pointer. - * @param dest Destination buffer. - * @param dOff Destination offset. - * @param size Size. - * @param timeout Operation timeout. - * @return Read bytes count. - * @throws IgniteCheckedException If space has been closed. - * @throws GridIpcSharedMemoryOperationTimedoutException If operation times out. - */ - static native long readSharedMemory(long shMemPtr, byte dest[], long dOff, long size, long timeout) - throws IgniteCheckedException, GridIpcSharedMemoryOperationTimedoutException; - - /** - * @param shmemPtr Shared memory pointer. - * @return Unread count. - */ - static native int unreadCount(long shmemPtr); - - /** - * @param shmemPtr Shared memory pointer. - * @return Shared memory ID. - */ - static native int sharedMemoryId(long shmemPtr); - - /** - * @param shmemPtr Shared memory pointer. - * @return Semaphore set ID. - */ - static native int semaphoreId(long shmemPtr); - - /** - * @param shMemPtr Shared memory pointer - * @param dest Destination buffer. - * @param dOff Destination offset. - * @param size Size. - * @param timeout Operation timeout. - * @return Read bytes count. - * @throws IgniteCheckedException If space has been closed. - * @throws GridIpcSharedMemoryOperationTimedoutException If operation times out. - */ - static native long readSharedMemoryByteBuffer(long shMemPtr, ByteBuffer dest, long dOff, long size, long timeout) - throws IgniteCheckedException, GridIpcSharedMemoryOperationTimedoutException; - - /** - * @param shMemPtr Shared memory pointer - * @param src Source buffer. - * @param sOff Offset. - * @param size Size. - * @param timeout Operation timeout. - * @throws IgniteCheckedException If space has been closed. - * @throws GridIpcSharedMemoryOperationTimedoutException If operation times out. - */ - static native void writeSharedMemory(long shMemPtr, byte src[], long sOff, long size, long timeout) - throws IgniteCheckedException, GridIpcSharedMemoryOperationTimedoutException; - - /** - * @param shMemPtr Shared memory pointer - * @param src Source buffer. - * @param sOff Offset. - * @param size Size. - * @param timeout Operation timeout. - * @throws IgniteCheckedException If space has been closed. - * @throws GridIpcSharedMemoryOperationTimedoutException If operation times out. - */ - static native void writeSharedMemoryByteBuffer(long shMemPtr, ByteBuffer src, long sOff, long size, long timeout) - throws IgniteCheckedException, GridIpcSharedMemoryOperationTimedoutException; - - /** @return PID of the current process (-1 on error). */ - public static int pid() { - // Should be something like this: 1160@mbp.local - String name = ManagementFactory.getRuntimeMXBean().getName(); - - try { - int idx = name.indexOf('@'); - - return idx > 0 ? Integer.parseInt(name.substring(0, idx)) : -1; - } - catch (NumberFormatException ignored) { - return -1; - } - } - - /** - * @param pid PID to check. - * @return {@code True} if process with passed ID is alive. - */ - static native boolean alive(int pid); - - /** - * Returns shared memory ids for Mac OS and Linux platforms. - * - * @return Collection of all shared memory IDs in the system. - * @throws IOException If failed. - * @throws InterruptedException If failed. - * @throws IllegalStateException If current OS is not supported. - */ - static Collection<Integer> sharedMemoryIds() throws IOException, InterruptedException { - if (U.isMacOs() || U.isLinux()) - return sharedMemoryIdsOnMacOS(); - else - throw new IllegalStateException("Current OS is not supported."); - } - - /** - * @param e Link error. - * @return Wrapping grid exception. - */ - static IgniteCheckedException linkError(UnsatisfiedLinkError e) { - return new IgniteCheckedException("Linkage error due to possible native library, libggshmem.so, " + - "version mismatch (stop all grid nodes, clean up your '/tmp' folder, and try again).", e); - } - - /** - * @return Shared memory IDs. - * @throws IOException If failed. - * @throws InterruptedException If failed. - */ - private static Collection<Integer> sharedMemoryIdsOnMacOS() throws IOException, InterruptedException { - // IPC status from <running system> as of Mon Jan 21 15:33:54 MSK 2013 - // T ID KEY MODE OWNER GROUP - // Shared Memory: - // m 327680 0x4702fd26 --rw-rw-rw- yzhdanov staff - - Process proc = Runtime.getRuntime().exec("ipcs -m"); - - BufferedReader rdr = new BufferedReader(new InputStreamReader(proc.getInputStream())); - - Collection<Integer> ret = new ArrayList<>(); - - try { - String line; - - while ((line = rdr.readLine()) != null) { - if (!line.startsWith(getPlatformDependentLineStartFlag())) - continue; - - String[] toks = line.split(" "); - - try { - ret.add(Integer.parseInt(toks[1])); - } - catch (NumberFormatException ignored) { - // No-op (just ignore). - } - } - - return ret; - } - finally { - proc.waitFor(); - } - } - - /** @return Flag for {@code ipcs} utility. */ - private static String getPlatformDependentLineStartFlag() { - if (U.isMacOs()) - return "m "; - else if (U.isLinux()) - return "0x"; - else - throw new IllegalStateException("This OS is not supported."); - } -}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/50f31e6e/modules/core/src/main/java/org/apache/ignite/internal/util/ipc/shmem/IpcSharedMemoryUtils.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/ipc/shmem/IpcSharedMemoryUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/util/ipc/shmem/IpcSharedMemoryUtils.java new file mode 100644 index 0000000..8fb7c6a --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/ipc/shmem/IpcSharedMemoryUtils.java @@ -0,0 +1,242 @@ +/* + * 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 org.apache.ignite.*; +import org.apache.ignite.internal.util.typedef.internal.*; + +import java.io.*; +import java.lang.management.*; +import java.nio.*; +import java.util.*; + +/** + * NOTE: Native library should be loaded, before methods of this class are called. Native library is loaded with: {@link + * GridIpcSharedMemoryNativeLoader#load()}. + */ +public class IpcSharedMemoryUtils { + /** + * Allocates shared memory segment and semaphores for IPC exchange. + * + * @param tokFileName OS token file name. + * @param size Memory space size in bytes. + * @param debug {@code True} to output debug to stdout (will set global flag). + * @return Shared memory pointer. + * @throws IgniteCheckedException If failed. + */ + static native long allocateSystemResources(String tokFileName, int size, boolean debug) + throws IgniteCheckedException; + + /** + * Attaches to previously allocated shared memory segment. + * + * @param shmemId OS shared memory segment ID. + * @param debug {@code True} to output debug to stdout (will set global flag). + * @return Shared memory pointer. + * @throws IgniteCheckedException If failed. + */ + static native long attach(int shmemId, boolean debug) throws IgniteCheckedException; + + /** + * Stops IPC communication. Call {@link #freeSystemResources(String, long, boolean)} after this call. + * + * @param shmemPtr Shared memory pointer. + */ + static native void ipcClose(long shmemPtr); + + /** + * Frees system resources. + * + * @param tokFileName Token file name. + * @param shmemPtr Shared memory pointer + * @param force {@code True} to force close. + */ + static native void freeSystemResources(String tokFileName, long shmemPtr, boolean force); + + /** + * Frees system resources. + * + * @param tokFileName Token file name. + * @param size Size. + */ + static native void freeSystemResources(String tokFileName, int size); + + /** + * @param shMemPtr Shared memory pointer. + * @param dest Destination buffer. + * @param dOff Destination offset. + * @param size Size. + * @param timeout Operation timeout. + * @return Read bytes count. + * @throws IgniteCheckedException If space has been closed. + * @throws GridIpcSharedMemoryOperationTimedoutException If operation times out. + */ + static native long readSharedMemory(long shMemPtr, byte dest[], long dOff, long size, long timeout) + throws IgniteCheckedException, GridIpcSharedMemoryOperationTimedoutException; + + /** + * @param shmemPtr Shared memory pointer. + * @return Unread count. + */ + static native int unreadCount(long shmemPtr); + + /** + * @param shmemPtr Shared memory pointer. + * @return Shared memory ID. + */ + static native int sharedMemoryId(long shmemPtr); + + /** + * @param shmemPtr Shared memory pointer. + * @return Semaphore set ID. + */ + static native int semaphoreId(long shmemPtr); + + /** + * @param shMemPtr Shared memory pointer + * @param dest Destination buffer. + * @param dOff Destination offset. + * @param size Size. + * @param timeout Operation timeout. + * @return Read bytes count. + * @throws IgniteCheckedException If space has been closed. + * @throws GridIpcSharedMemoryOperationTimedoutException If operation times out. + */ + static native long readSharedMemoryByteBuffer(long shMemPtr, ByteBuffer dest, long dOff, long size, long timeout) + throws IgniteCheckedException, GridIpcSharedMemoryOperationTimedoutException; + + /** + * @param shMemPtr Shared memory pointer + * @param src Source buffer. + * @param sOff Offset. + * @param size Size. + * @param timeout Operation timeout. + * @throws IgniteCheckedException If space has been closed. + * @throws GridIpcSharedMemoryOperationTimedoutException If operation times out. + */ + static native void writeSharedMemory(long shMemPtr, byte src[], long sOff, long size, long timeout) + throws IgniteCheckedException, GridIpcSharedMemoryOperationTimedoutException; + + /** + * @param shMemPtr Shared memory pointer + * @param src Source buffer. + * @param sOff Offset. + * @param size Size. + * @param timeout Operation timeout. + * @throws IgniteCheckedException If space has been closed. + * @throws GridIpcSharedMemoryOperationTimedoutException If operation times out. + */ + static native void writeSharedMemoryByteBuffer(long shMemPtr, ByteBuffer src, long sOff, long size, long timeout) + throws IgniteCheckedException, GridIpcSharedMemoryOperationTimedoutException; + + /** @return PID of the current process (-1 on error). */ + public static int pid() { + // Should be something like this: 1160@mbp.local + String name = ManagementFactory.getRuntimeMXBean().getName(); + + try { + int idx = name.indexOf('@'); + + return idx > 0 ? Integer.parseInt(name.substring(0, idx)) : -1; + } + catch (NumberFormatException ignored) { + return -1; + } + } + + /** + * @param pid PID to check. + * @return {@code True} if process with passed ID is alive. + */ + static native boolean alive(int pid); + + /** + * Returns shared memory ids for Mac OS and Linux platforms. + * + * @return Collection of all shared memory IDs in the system. + * @throws IOException If failed. + * @throws InterruptedException If failed. + * @throws IllegalStateException If current OS is not supported. + */ + static Collection<Integer> sharedMemoryIds() throws IOException, InterruptedException { + if (U.isMacOs() || U.isLinux()) + return sharedMemoryIdsOnMacOS(); + else + throw new IllegalStateException("Current OS is not supported."); + } + + /** + * @param e Link error. + * @return Wrapping grid exception. + */ + static IgniteCheckedException linkError(UnsatisfiedLinkError e) { + return new IgniteCheckedException("Linkage error due to possible native library, libggshmem.so, " + + "version mismatch (stop all grid nodes, clean up your '/tmp' folder, and try again).", e); + } + + /** + * @return Shared memory IDs. + * @throws IOException If failed. + * @throws InterruptedException If failed. + */ + private static Collection<Integer> sharedMemoryIdsOnMacOS() throws IOException, InterruptedException { + // IPC status from <running system> as of Mon Jan 21 15:33:54 MSK 2013 + // T ID KEY MODE OWNER GROUP + // Shared Memory: + // m 327680 0x4702fd26 --rw-rw-rw- yzhdanov staff + + Process proc = Runtime.getRuntime().exec("ipcs -m"); + + BufferedReader rdr = new BufferedReader(new InputStreamReader(proc.getInputStream())); + + Collection<Integer> ret = new ArrayList<>(); + + try { + String line; + + while ((line = rdr.readLine()) != null) { + if (!line.startsWith(getPlatformDependentLineStartFlag())) + continue; + + String[] toks = line.split(" "); + + try { + ret.add(Integer.parseInt(toks[1])); + } + catch (NumberFormatException ignored) { + // No-op (just ignore). + } + } + + return ret; + } + finally { + proc.waitFor(); + } + } + + /** @return Flag for {@code ipcs} utility. */ + private static String getPlatformDependentLineStartFlag() { + if (U.isMacOs()) + return "m "; + else if (U.isLinux()) + return "0x"; + else + throw new IllegalStateException("This OS is not supported."); + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/50f31e6e/modules/core/src/test/java/org/apache/ignite/internal/util/ipc/shmem/GridIpcSharedMemoryCrashDetectionSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/util/ipc/shmem/GridIpcSharedMemoryCrashDetectionSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/util/ipc/shmem/GridIpcSharedMemoryCrashDetectionSelfTest.java index d6a2049..37468f1 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/util/ipc/shmem/GridIpcSharedMemoryCrashDetectionSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/util/ipc/shmem/GridIpcSharedMemoryCrashDetectionSelfTest.java @@ -61,7 +61,7 @@ public class GridIpcSharedMemoryCrashDetectionSelfTest extends GridCommonAbstrac info("Check that server gets correct exception upon client's killing."); - info("Shared memory IDs before starting client endpoint: " + GridIpcSharedMemoryUtils.sharedMemoryIds()); + info("Shared memory IDs before starting client endpoint: " + IpcSharedMemoryUtils.sharedMemoryIds()); Collection<Integer> shmemIdsWithinInteractions = interactWithClient(srv, true); @@ -69,7 +69,7 @@ public class GridIpcSharedMemoryCrashDetectionSelfTest extends GridCommonAbstrac // Give server endpoint some time to make resource clean up. See GridIpcSharedMemoryServerEndpoint.GC_FREQ. for (int i = 0; i < 12; i++) { - shmemIdsAfterInteractions = GridIpcSharedMemoryUtils.sharedMemoryIds(); + shmemIdsAfterInteractions = IpcSharedMemoryUtils.sharedMemoryIds(); info("Shared memory IDs created within interaction: " + shmemIdsWithinInteractions); info("Shared memory IDs after killing client endpoint: " + shmemIdsAfterInteractions); @@ -93,13 +93,13 @@ public class GridIpcSharedMemoryCrashDetectionSelfTest extends GridCommonAbstrac * @throws Exception If failed. */ public void testGgfsClientServerInteractionsUponServerKilling() throws Exception { - Collection<Integer> shmemIdsBeforeInteractions = GridIpcSharedMemoryUtils.sharedMemoryIds(); + Collection<Integer> shmemIdsBeforeInteractions = IpcSharedMemoryUtils.sharedMemoryIds(); info("Shared memory IDs before starting server-client interactions: " + shmemIdsBeforeInteractions); Collection<Integer> shmemIdsWithinInteractions = interactWithServer(); - Collection<Integer> shmemIdsAfterInteractions = GridIpcSharedMemoryUtils.sharedMemoryIds(); + Collection<Integer> shmemIdsAfterInteractions = IpcSharedMemoryUtils.sharedMemoryIds(); info("Shared memory IDs created within interaction: " + shmemIdsWithinInteractions); info("Shared memory IDs after server and client killing: " + shmemIdsAfterInteractions); @@ -117,7 +117,7 @@ public class GridIpcSharedMemoryCrashDetectionSelfTest extends GridCommonAbstrac try { // Give server endpoint some time to make resource clean up. See GridIpcSharedMemoryServerEndpoint.GC_FREQ. for (int i = 0; i < 12; i++) { - shmemIdsAfterInteractions = GridIpcSharedMemoryUtils.sharedMemoryIds(); + shmemIdsAfterInteractions = IpcSharedMemoryUtils.sharedMemoryIds(); info("Shared memory IDs after server restart: " + shmemIdsAfterInteractions); @@ -143,11 +143,11 @@ public class GridIpcSharedMemoryCrashDetectionSelfTest extends GridCommonAbstrac */ public void testClientThrowsCorrectExceptionUponServerKilling() throws Exception { info("Shared memory IDs before starting server-client interactions: " + - GridIpcSharedMemoryUtils.sharedMemoryIds()); + IpcSharedMemoryUtils.sharedMemoryIds()); Collection<Integer> shmemIdsWithinInteractions = checkClientThrowsCorrectExceptionUponServerKilling(); - Collection<Integer> shmemIdsAfterInteractions = GridIpcSharedMemoryUtils.sharedMemoryIds(); + Collection<Integer> shmemIdsAfterInteractions = IpcSharedMemoryUtils.sharedMemoryIds(); info("Shared memory IDs created within interaction: " + shmemIdsWithinInteractions); info("Shared memory IDs after server killing and client graceful termination: " + shmemIdsAfterInteractions); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/50f31e6e/modules/core/src/test/java/org/apache/ignite/internal/util/ipc/shmem/GridIpcSharedMemorySpaceSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/util/ipc/shmem/GridIpcSharedMemorySpaceSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/util/ipc/shmem/GridIpcSharedMemorySpaceSelfTest.java index 1d24f02..f443122 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/util/ipc/shmem/GridIpcSharedMemorySpaceSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/util/ipc/shmem/GridIpcSharedMemorySpaceSelfTest.java @@ -154,14 +154,14 @@ public class GridIpcSharedMemorySpaceSelfTest extends GridCommonAbstractTest { info("Using token file: " + tok); - Collection<Integer> ids = GridIpcSharedMemoryUtils.sharedMemoryIds(); + Collection<Integer> ids = IpcSharedMemoryUtils.sharedMemoryIds(); info("IDs in the system: " + ids); - GridIpcSharedMemorySpace space = new GridIpcSharedMemorySpace(tok, GridIpcSharedMemoryUtils.pid(), 0, 128, + GridIpcSharedMemorySpace space = new GridIpcSharedMemorySpace(tok, IpcSharedMemoryUtils.pid(), 0, 128, false, log); - ids = GridIpcSharedMemoryUtils.sharedMemoryIds(); + ids = IpcSharedMemoryUtils.sharedMemoryIds(); info("IDs in the system: " + ids); @@ -174,7 +174,7 @@ public class GridIpcSharedMemorySpaceSelfTest extends GridCommonAbstractTest { space.forceClose(); - ids = GridIpcSharedMemoryUtils.sharedMemoryIds(); + ids = IpcSharedMemoryUtils.sharedMemoryIds(); info("IDs in the system: " + ids); @@ -195,10 +195,10 @@ public class GridIpcSharedMemorySpaceSelfTest extends GridCommonAbstractTest { info("Using token file: " + tok); - GridIpcSharedMemorySpace spaceOut = new GridIpcSharedMemorySpace(tok, GridIpcSharedMemoryUtils.pid(), 0, 128, + GridIpcSharedMemorySpace spaceOut = new GridIpcSharedMemorySpace(tok, IpcSharedMemoryUtils.pid(), 0, 128, false, log); - try (GridIpcSharedMemorySpace spaceIn = new GridIpcSharedMemorySpace(tok, GridIpcSharedMemoryUtils.pid(), 0, + try (GridIpcSharedMemorySpace spaceIn = new GridIpcSharedMemorySpace(tok, IpcSharedMemoryUtils.pid(), 0, 128, true, spaceOut.sharedMemoryId(), log)) { // Write some data to the space, but avoid blocking. spaceOut.write(DATA, 0, 16, 0); @@ -233,11 +233,11 @@ public class GridIpcSharedMemorySpaceSelfTest extends GridCommonAbstractTest { info("Using token file: " + tok); - try (GridIpcSharedMemorySpace spaceOut = new GridIpcSharedMemorySpace(tok, GridIpcSharedMemoryUtils.pid(), - GridIpcSharedMemoryUtils.pid(), 128, false, log)) { + try (GridIpcSharedMemorySpace spaceOut = new GridIpcSharedMemorySpace(tok, IpcSharedMemoryUtils.pid(), + IpcSharedMemoryUtils.pid(), 128, false, log)) { - try (GridIpcSharedMemorySpace spaceIn = new GridIpcSharedMemorySpace(tok, GridIpcSharedMemoryUtils.pid(), - GridIpcSharedMemoryUtils.pid(), 128, true, spaceOut.sharedMemoryId(), log)) { + try (GridIpcSharedMemorySpace spaceIn = new GridIpcSharedMemorySpace(tok, IpcSharedMemoryUtils.pid(), + IpcSharedMemoryUtils.pid(), 128, true, spaceOut.sharedMemoryId(), log)) { // Write some data to the space, but avoid blocking. spaceOut.write(DATA, 0, 16, 0); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/50f31e6e/modules/core/src/test/java/org/apache/ignite/internal/util/ipc/shmem/GridIpcSharedMemoryUtilsSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/util/ipc/shmem/GridIpcSharedMemoryUtilsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/util/ipc/shmem/GridIpcSharedMemoryUtilsSelfTest.java deleted file mode 100644 index 21d2917..0000000 --- a/modules/core/src/test/java/org/apache/ignite/internal/util/ipc/shmem/GridIpcSharedMemoryUtilsSelfTest.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * 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 org.apache.ignite.*; -import org.apache.ignite.testframework.junits.common.*; - -import java.io.*; -import java.util.*; - -/** - * - */ -public class GridIpcSharedMemoryUtilsSelfTest extends GridCommonAbstractTest { - /** {@inheritDoc} */ - @Override protected void beforeTestsStarted() throws Exception { - super.beforeTestsStarted(); - - GridIpcSharedMemoryNativeLoader.load(); - } - - /** - * @throws Exception If failed. - */ - public void testPid() throws Exception { - int pid = GridIpcSharedMemoryUtils.pid(); - - info("PID of the current process: " + pid); - - assert GridIpcSharedMemoryUtils.alive(pid); - - // PID cannot have this value. - assert !GridIpcSharedMemoryUtils.alive(Integer.MAX_VALUE) : "Alive PID: " + Integer.MAX_VALUE; - } - - /** - * @throws Exception If failed. - */ - public void testIdsGet() throws Exception { - File tokFile = new File(IgniteSystemProperties.getString("java.io.tmpdir"), getTestGridName()); - - assert tokFile.createNewFile() || tokFile.exists(); - - String tok = tokFile.getAbsolutePath(); - - GridIpcSharedMemorySpace space = new GridIpcSharedMemorySpace(tok, GridIpcSharedMemoryUtils.pid(), 0, 128, - false, log); - - info("Space: " + space); - - int shmemId = space.sharedMemoryId(); - - try { - // Write some data to the space, but avoid blocking. - space.write(new byte[] {0, 1, 2, 3}, 0, 4, 0); - - Collection<Integer> ids = GridIpcSharedMemoryUtils.sharedMemoryIds(); - - info("IDs: " + ids); - - assertTrue(ids.contains(shmemId)); - } - finally { - space.forceClose(); - } - - assertFalse(GridIpcSharedMemoryUtils.sharedMemoryIds().contains(shmemId)); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/50f31e6e/modules/core/src/test/java/org/apache/ignite/internal/util/ipc/shmem/IpcSharedMemoryUtilsSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/util/ipc/shmem/IpcSharedMemoryUtilsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/util/ipc/shmem/IpcSharedMemoryUtilsSelfTest.java new file mode 100644 index 0000000..028cae9 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/util/ipc/shmem/IpcSharedMemoryUtilsSelfTest.java @@ -0,0 +1,84 @@ +/* + * 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 org.apache.ignite.*; +import org.apache.ignite.testframework.junits.common.*; + +import java.io.*; +import java.util.*; + +/** + * + */ +public class IpcSharedMemoryUtilsSelfTest extends GridCommonAbstractTest { + /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + super.beforeTestsStarted(); + + GridIpcSharedMemoryNativeLoader.load(); + } + + /** + * @throws Exception If failed. + */ + public void testPid() throws Exception { + int pid = IpcSharedMemoryUtils.pid(); + + info("PID of the current process: " + pid); + + assert IpcSharedMemoryUtils.alive(pid); + + // PID cannot have this value. + assert !IpcSharedMemoryUtils.alive(Integer.MAX_VALUE) : "Alive PID: " + Integer.MAX_VALUE; + } + + /** + * @throws Exception If failed. + */ + public void testIdsGet() throws Exception { + File tokFile = new File(IgniteSystemProperties.getString("java.io.tmpdir"), getTestGridName()); + + assert tokFile.createNewFile() || tokFile.exists(); + + String tok = tokFile.getAbsolutePath(); + + GridIpcSharedMemorySpace space = new GridIpcSharedMemorySpace(tok, IpcSharedMemoryUtils.pid(), 0, 128, + false, log); + + info("Space: " + space); + + int shmemId = space.sharedMemoryId(); + + try { + // Write some data to the space, but avoid blocking. + space.write(new byte[] {0, 1, 2, 3}, 0, 4, 0); + + Collection<Integer> ids = IpcSharedMemoryUtils.sharedMemoryIds(); + + info("IDs: " + ids); + + assertTrue(ids.contains(shmemId)); + } + finally { + space.forceClose(); + } + + assertFalse(IpcSharedMemoryUtils.sharedMemoryIds().contains(shmemId)); + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/50f31e6e/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteIpcSharedMemorySelfTestSuite.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteIpcSharedMemorySelfTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteIpcSharedMemorySelfTestSuite.java index 395c3bb..6b6d49d 100644 --- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteIpcSharedMemorySelfTestSuite.java +++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteIpcSharedMemorySelfTestSuite.java @@ -32,7 +32,7 @@ public class IgniteIpcSharedMemorySelfTestSuite extends TestSuite { TestSuite suite = new TestSuite("Ignite IPC Shared Memory Test Suite."); suite.addTest(new TestSuite(GridIpcSharedMemorySpaceSelfTest.class)); - suite.addTest(new TestSuite(GridIpcSharedMemoryUtilsSelfTest.class)); + suite.addTest(new TestSuite(IpcSharedMemoryUtilsSelfTest.class)); suite.addTest(new TestSuite(GridIpcSharedMemoryCrashDetectionSelfTest.class)); suite.addTest(new TestSuite(GridIpcSharedMemoryNativeLoaderSelfTest.class));