You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by vo...@apache.org on 2015/05/18 15:58:35 UTC

[40/47] incubator-ignite git commit: # added test

# added test


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

Branch: refs/heads/ignite-gg-9614
Commit: a27a35d8bfd4954b5f6b912e2d5dd54f75c31f3c
Parents: da5a228
Author: sboikov <se...@inria.fr>
Authored: Sat May 16 06:56:15 2015 +0300
Committer: sboikov <se...@inria.fr>
Committed: Sat May 16 06:56:15 2015 +0300

----------------------------------------------------------------------
 .../near/IgniteCacheNearOnlyTxTest.java         | 140 +++++++++++++++++++
 1 file changed, 140 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a27a35d8/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheNearOnlyTxTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheNearOnlyTxTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheNearOnlyTxTest.java
new file mode 100644
index 0000000..06a4bfc
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheNearOnlyTxTest.java
@@ -0,0 +1,140 @@
+/*
+ * 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.processors.cache.distributed.near;
+
+import org.apache.ignite.*;
+import org.apache.ignite.cache.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.internal.processors.cache.*;
+import org.apache.ignite.testframework.*;
+import org.apache.ignite.transactions.*;
+
+import java.util.concurrent.*;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.*;
+import static org.apache.ignite.transactions.TransactionConcurrency.*;
+import static org.apache.ignite.transactions.TransactionIsolation.*;
+
+/**
+ *
+ */
+public class IgniteCacheNearOnlyTxTest extends IgniteCacheAbstractTest {
+    /** {@inheritDoc} */
+    @Override protected int gridCount() {
+        return 2;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheMode cacheMode() {
+        return CacheMode.PARTITIONED;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheAtomicityMode atomicityMode() {
+        return TRANSACTIONAL;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected NearCacheConfiguration nearConfiguration() {
+        return null;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        if (getTestGridName(1).equals(gridName)) {
+            cfg.setClientMode(true);
+
+            cfg.setCacheConfiguration();
+        }
+
+        return cfg;
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testNearOnlyPutMultithreaded() throws Exception {
+        final Ignite ignite1 = ignite(1);
+
+        assertTrue(ignite1.configuration().isClientMode());
+
+        ignite1.createNearCache(null, new NearCacheConfiguration<>());
+
+        GridTestUtils.runMultiThreaded(new Callable<Object>() {
+            @Override public Object call() throws Exception {
+                IgniteCache cache = ignite1.cache(null);
+
+                int key = 1;
+
+                for (int i = 0; i < 100; i++)
+                    cache.put(key, 1);
+
+                return null;
+            }
+        }, 5, "put-thread");
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testOptimisticTx() throws Exception {
+        txMultithreaded(true);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPessimisticTx() throws Exception {
+        txMultithreaded(false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    private void txMultithreaded(final boolean optimistic) throws Exception {
+        final Ignite ignite1 = ignite(1);
+
+        assertTrue(ignite1.configuration().isClientMode());
+
+        ignite1.createNearCache(null, new NearCacheConfiguration<>());
+
+        GridTestUtils.runMultiThreaded(new Callable<Object>() {
+            @Override public Object call() throws Exception {
+                IgniteCache cache = ignite1.cache(null);
+
+                int key = 1;
+
+                IgniteTransactions txs = ignite1.transactions();
+
+                for (int i = 0; i < 100; i++) {
+                    try (Transaction tx = txs.txStart(optimistic ? OPTIMISTIC : PESSIMISTIC, REPEATABLE_READ)) {
+                        cache.get(key);
+
+                        cache.put(key, 1);
+
+                        tx.commit();
+                    }
+                }
+
+                return null;
+            }
+        }, 5, "put-thread");
+    }
+}