Skip to content

Commit

Permalink
IGNITE-56 Change all tests to use new cache API, add JCache TCK (4)
Browse files Browse the repository at this point in the history
  • Loading branch information
sevdokimov-gg committed Feb 2, 2015
1 parent c10fad8 commit 625b33f
Show file tree
Hide file tree
Showing 13 changed files with 193 additions and 469 deletions.

Large diffs are not rendered by default.

Expand Up @@ -56,11 +56,11 @@ public GridCacheNearOneNodeSelfTest() {
@Override protected void afterTest() throws Exception { @Override protected void afterTest() throws Exception {
store.reset(); store.reset();


cache().removeAll(); jcache().removeAll();


assertEquals("DHT entries: " + dht().entries(), 0, dht().size()); assertEquals("DHT entries: " + dht().entries(), 0, dht().size());
assertEquals("Near entries: " + near().entries(), 0, near().size()); assertEquals("Near entries: " + near().entries(), 0, near().size());
assertEquals("Cache entries: " + cache().entrySet(), 0, cache().size()); assertEquals(0, jcache().size());
} }


/** {@inheritDoc} */ /** {@inheritDoc} */
Expand Down Expand Up @@ -95,35 +95,35 @@ public GridCacheNearOneNodeSelfTest() {


/** @throws Exception If failed. */ /** @throws Exception If failed. */
public void testRemove() throws Exception { public void testRemove() throws Exception {
GridCache<Integer, String> near = cache(); IgniteCache<Object, Object> near = jcache();


assertEquals("DHT entries: " + dht().entries(), 0, dht().size()); assertEquals("DHT entries: " + dht().entries(), 0, dht().size());
assertEquals("Near entries: " + near().entries(), 0, near().size()); assertEquals("Near entries: " + near().entries(), 0, near().size());
assertEquals("Cache entries: " + cache().entrySet(), 0, cache().size()); assertEquals(0, near.size());


for (int i = 0; i < 10; i++) for (int i = 0; i < 10; i++)
near.put(i, Integer.toString(i)); near.put(i, Integer.toString(i));


assertEquals("DHT entries: " + dht().entries(), 10, dht().size()); assertEquals("DHT entries: " + dht().entries(), 10, dht().size());
assertEquals("Near entries: " + near().entries(), 10, near().size()); assertEquals("Near entries: " + near().entries(), 10, near().size());
assertEquals("Cache entries: " + cache().entrySet(), 10, cache().size()); assertEquals(10, near.size());


cache().remove(0); near.remove(0);


assertEquals("DHT entries: " + dht().entries(), 9, dht().size()); assertEquals("DHT entries: " + dht().entries(), 9, dht().size());
assertEquals("Near entries: " + near().entries(), 9, near().size()); assertEquals("Near entries: " + near().entries(), 9, near().size());
assertEquals("Cache entries: " + cache().entrySet(), 9, cache().size()); assertEquals(9, near.size());


cache().removeAll(); near.removeAll();


assertEquals("DHT entries: " + dht().entries(), 0, dht().size()); assertEquals("DHT entries: " + dht().entries(), 0, dht().size());
assertEquals("Near entries: " + near().entries(), 0, near().size()); assertEquals("Near entries: " + near().entries(), 0, near().size());
assertEquals("Cache entries: " + cache().entrySet(), 0, cache().size()); assertEquals(0, near.size());
} }


/** @throws Exception If failed. */ /** @throws Exception If failed. */
public void testReadThrough() throws Exception { public void testReadThrough() throws Exception {
GridCache<Integer, String> near = cache(); IgniteCache<Integer, String> near = jcache();


GridCache<Integer, String> dht = dht(); GridCache<Integer, String> dht = dht();


Expand Down Expand Up @@ -153,11 +153,11 @@ public void testReadThrough() throws Exception {
*/ */
@SuppressWarnings({"ConstantConditions"}) @SuppressWarnings({"ConstantConditions"})
public void testOptimisticTxWriteThrough() throws Exception { public void testOptimisticTxWriteThrough() throws Exception {
GridCache<Integer, String> near = cache(); IgniteCache<Object, Object> near = jcache();
GridCacheAdapter<Integer, String> dht = dht(); GridCacheAdapter<Integer, String> dht = dht();


try (IgniteTx tx = cache().txStart(OPTIMISTIC, REPEATABLE_READ) ) { try (IgniteTx tx = grid().transactions().txStart(OPTIMISTIC, REPEATABLE_READ) ) {
near.putx(2, "2"); near.put(2, "2");
near.put(3, "3"); near.put(3, "3");


assert "2".equals(near.get(2)); assert "2".equals(near.get(2));
Expand Down Expand Up @@ -283,14 +283,14 @@ public void testSingleLockReentry() throws Exception {


/** @throws Exception If failed. */ /** @throws Exception If failed. */
public void testTransactionSingleGet() throws Exception { public void testTransactionSingleGet() throws Exception {
GridCache<Integer, String> cache = cache(); IgniteCache<Object, Object> cache = jcache();


cache.put(1, "val1"); cache.put(1, "val1");


assertEquals("val1", dht().peek(1)); assertEquals("val1", dht().peek(1));
assertNull(near().peekNearOnly(1)); assertNull(near().peekNearOnly(1));


IgniteTx tx = cache.txStart(PESSIMISTIC, REPEATABLE_READ); IgniteTx tx = grid().transactions().txStart(PESSIMISTIC, REPEATABLE_READ);


assertEquals("val1", cache.get(1)); assertEquals("val1", cache.get(1));


Expand All @@ -302,18 +302,18 @@ public void testTransactionSingleGet() throws Exception {


/** @throws Exception If failed. */ /** @throws Exception If failed. */
public void testTransactionSingleGetRemove() throws Exception { public void testTransactionSingleGetRemove() throws Exception {
GridCache<Integer, String> cache = cache(); IgniteCache<Object, Object> cache = jcache();


cache.put(1, "val1"); cache.put(1, "val1");


assertEquals("val1", dht().peek(1)); assertEquals("val1", dht().peek(1));
assertNull(near().peekNearOnly(1)); assertNull(near().peekNearOnly(1));


IgniteTx tx = cache.txStart(PESSIMISTIC, REPEATABLE_READ); IgniteTx tx = grid().transactions().txStart(PESSIMISTIC, REPEATABLE_READ);


assertEquals("val1", cache.get(1)); assertEquals("val1", cache.get(1));


assertTrue(cache.removex(1)); assertTrue(cache.remove(1));


tx.commit(); tx.commit();


Expand Down
Expand Up @@ -432,9 +432,9 @@ public void testImplicitLockReaders() throws Exception {


assertEquals(grid(1).localNode(), F.first(aff.nodes(aff.partition(key2), grid(1).nodes()))); assertEquals(grid(1).localNode(), F.first(aff.nodes(aff.partition(key2), grid(1).nodes())));


GridCache<Integer, String> cache = cache(0); IgniteCache<Integer, String> cache = jcache(0);


assertNull(cache.put(key1, val1)); assertNull(cache.getAndPut(key1, val1));


assertEquals(val1, dht(0).peek(key1)); assertEquals(val1, dht(0).peek(key1));
assertEquals(val1, dht(1).peek(key1)); assertEquals(val1, dht(1).peek(key1));
Expand All @@ -444,7 +444,7 @@ public void testImplicitLockReaders() throws Exception {
assertNull(near(1).peekNearOnly(key1)); assertNull(near(1).peekNearOnly(key1));
assertNull(near(2).peekNearOnly(key1)); assertNull(near(2).peekNearOnly(key1));


assertTrue(cache.putx(key2, val2)); cache.put(key2, val2);


assertNull(dht(0).peek(key2)); assertNull(dht(0).peek(key2));
assertEquals(val2, dht(1).peek(key2)); assertEquals(val2, dht(1).peek(key2));
Expand Down Expand Up @@ -487,12 +487,10 @@ public void testImplicitLockReaders() throws Exception {
assertNull(near(2).peekNearOnly(key1)); assertNull(near(2).peekNearOnly(key1));


for (int i = 0; i < grids; i++) { for (int i = 0; i < grids; i++) {
assert !cache(i).isLocked(key1); assert !jcache(i).isLocalLocked(key1, false);
assert !cache(i).isLocked(key2); assert !jcache(i).isLocalLocked(key2, false);


assert cache(i).size() == 0; assert jcache(i).localSize() == 0;
assert cache(i).isEmpty();
assert cache(i).size() == 0;
} }
} }


Expand Down
Expand Up @@ -17,6 +17,7 @@


package org.apache.ignite.internal.processors.cache.distributed.near; package org.apache.ignite.internal.processors.cache.distributed.near;


import org.apache.ignite.*;
import org.apache.ignite.cache.*; import org.apache.ignite.cache.*;
import org.apache.ignite.cluster.*; import org.apache.ignite.cluster.*;
import org.apache.ignite.configuration.*; import org.apache.ignite.configuration.*;
Expand Down Expand Up @@ -60,7 +61,7 @@ public class GridCachePartitionedBasicStoreMultiNodeSelfTest extends GridCommonA
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override protected void afterTest() throws Exception { @Override protected void afterTest() throws Exception {
for (int i = 0; i < GRID_CNT; i++) for (int i = 0; i < GRID_CNT; i++)
cache(i).removeAll(); jcache(i).removeAll();


for (GridCacheTestStore store : stores) for (GridCacheTestStore store : stores)
store.reset(); store.reset();
Expand Down Expand Up @@ -124,15 +125,15 @@ protected CacheDistributionMode mode() {
* @throws Exception If failed. * @throws Exception If failed.
*/ */
public void testPutFromPrimary() throws Exception { public void testPutFromPrimary() throws Exception {
GridCache<Integer, String> cache = cache(0); IgniteCache<Integer, String> cache = jcache(0);


int key = 0; int key = 0;


while (true) { while (true) {
boolean found = false; boolean found = false;


for (ClusterNode n : grid(0).nodes()) { for (ClusterNode n : grid(0).nodes()) {
if (cache.affinity().isPrimary(n, key)) { if (grid(0).affinity(null).isPrimary(n, key)) {
found = true; found = true;


break; break;
Expand All @@ -143,7 +144,7 @@ public void testPutFromPrimary() throws Exception {
break; break;
} }


assertNull(cache.put(key, "val")); assertNull(cache.getAndPut(key, "val"));


checkStoreUsage(1, 1, 0, 1); checkStoreUsage(1, 1, 0, 1);
} }
Expand All @@ -152,15 +153,15 @@ public void testPutFromPrimary() throws Exception {
* @throws Exception If failed. * @throws Exception If failed.
*/ */
public void testPutFromBackup() throws Exception { public void testPutFromBackup() throws Exception {
GridCache<Integer, String> cache = cache(0); IgniteCache<Integer, String> cache = jcache(0);


int key = 0; int key = 0;


while (true) { while (true) {
boolean found = false; boolean found = false;


for (ClusterNode n : grid(0).nodes()) { for (ClusterNode n : grid(0).nodes()) {
if (cache.affinity().isBackup(n, key)) { if (grid(0).affinity(null).isBackup(n, key)) {
found = true; found = true;


break; break;
Expand All @@ -171,7 +172,7 @@ public void testPutFromBackup() throws Exception {
break; break;
} }


assertNull(cache.put(key, "val")); assertNull(cache.getAndPut(key, "val"));


checkStoreUsage(1, 1, 0, 1); checkStoreUsage(1, 1, 0, 1);
} }
Expand All @@ -180,15 +181,15 @@ public void testPutFromBackup() throws Exception {
* @throws Exception If failed. * @throws Exception If failed.
*/ */
public void testPutFromNear() throws Exception { public void testPutFromNear() throws Exception {
GridCache<Integer, String> cache = cache(0); IgniteCache<Integer, String> cache = jcache(0);


int key = 0; int key = 0;


while (true) { while (true) {
boolean found = false; boolean found = false;


for (ClusterNode n : grid(0).nodes()) { for (ClusterNode n : grid(0).nodes()) {
if (!cache.affinity().isPrimaryOrBackup(n, key)) { if (!grid(0).affinity(null).isPrimaryOrBackup(n, key)) {
found = true; found = true;


break; break;
Expand All @@ -199,7 +200,7 @@ public void testPutFromNear() throws Exception {
break; break;
} }


assertNull(cache.put(key, "val")); assertNull(cache.getAndPut(key, "val"));


checkStoreUsage(1, 1, 0, 1); checkStoreUsage(1, 1, 0, 1);
} }
Expand All @@ -208,15 +209,15 @@ public void testPutFromNear() throws Exception {
* @throws Exception If failed. * @throws Exception If failed.
*/ */
public void testPutIfAbsentFromPrimary() throws Exception { public void testPutIfAbsentFromPrimary() throws Exception {
GridCache<Integer, String> cache = cache(0); IgniteCache<Integer, String> cache = jcache(0);


int key = 0; int key = 0;


while (true) { while (true) {
boolean found = false; boolean found = false;


for (ClusterNode n : grid(0).nodes()) { for (ClusterNode n : grid(0).nodes()) {
if (cache.affinity().isPrimary(n, key)) { if (grid(0).affinity(null).isPrimary(n, key)) {
found = true; found = true;


break; break;
Expand All @@ -227,7 +228,7 @@ public void testPutIfAbsentFromPrimary() throws Exception {
break; break;
} }


assertNull(cache.putIfAbsent(key, "val")); assertTrue(cache.putIfAbsent(key, "val"));


checkStoreUsage(1, 1, 0, 1); checkStoreUsage(1, 1, 0, 1);
} }
Expand All @@ -236,15 +237,15 @@ public void testPutIfAbsentFromPrimary() throws Exception {
* @throws Exception If failed. * @throws Exception If failed.
*/ */
public void testPutIfAbsentFromBackup() throws Exception { public void testPutIfAbsentFromBackup() throws Exception {
GridCache<Integer, String> cache = cache(0); IgniteCache<Integer, String> cache = jcache(0);


int key = 0; int key = 0;


while (true) { while (true) {
boolean found = false; boolean found = false;


for (ClusterNode n : grid(0).nodes()) { for (ClusterNode n : grid(0).nodes()) {
if (cache.affinity().isBackup(n, key)) { if (grid(0).affinity(null).isBackup(n, key)) {
found = true; found = true;


break; break;
Expand All @@ -255,7 +256,7 @@ public void testPutIfAbsentFromBackup() throws Exception {
break; break;
} }


assertNull(cache.putIfAbsent(key, "val")); assertTrue(cache.putIfAbsent(key, "val"));


checkStoreUsage(1, 1, 0, 1); checkStoreUsage(1, 1, 0, 1);
} }
Expand All @@ -264,15 +265,15 @@ public void testPutIfAbsentFromBackup() throws Exception {
* @throws Exception If failed. * @throws Exception If failed.
*/ */
public void testPutIfAbsentFromNear() throws Exception { public void testPutIfAbsentFromNear() throws Exception {
GridCache<Integer, String> cache = cache(0); IgniteCache<Integer, String> cache = jcache(0);


int key = 0; int key = 0;


while (true) { while (true) {
boolean found = false; boolean found = false;


for (ClusterNode n : grid(0).nodes()) { for (ClusterNode n : grid(0).nodes()) {
if (!cache.affinity().isPrimaryOrBackup(n, key)) { if (!grid(0).affinity(null).isPrimaryOrBackup(n, key)) {
found = true; found = true;


break; break;
Expand All @@ -283,7 +284,7 @@ public void testPutIfAbsentFromNear() throws Exception {
break; break;
} }


assertNull(cache.putIfAbsent(key, "val")); assertTrue(cache.putIfAbsent(key, "val"));


checkStoreUsage(1, 1, 0, 1); checkStoreUsage(1, 1, 0, 1);
} }
Expand All @@ -292,9 +293,9 @@ public void testPutIfAbsentFromNear() throws Exception {
* @throws Exception If failed. * @throws Exception If failed.
*/ */
public void testPutAll() throws Exception { public void testPutAll() throws Exception {
GridCache<Integer, String> cache = cache(0); IgniteCache<Integer, String> cache = jcache(0);


Map<Integer, String> map = new HashMap<>(10); Map<Integer, String> map = new HashMap<>();


for (int i = 0; i < 10; i++) for (int i = 0; i < 10; i++)
map.put(i, "val"); map.put(i, "val");
Expand All @@ -308,9 +309,9 @@ public void testPutAll() throws Exception {
* @throws Exception If failed. * @throws Exception If failed.
*/ */
public void testMultipleOperations() throws Exception { public void testMultipleOperations() throws Exception {
GridCache<Integer, String> cache = cache(0); IgniteCache<Integer, String> cache = jcache(0);


try (IgniteTx tx = cache.txStart(OPTIMISTIC, REPEATABLE_READ)) { try (IgniteTx tx = grid(0).transactions().txStart(OPTIMISTIC, REPEATABLE_READ)) {
cache.put(1, "val"); cache.put(1, "val");
cache.put(2, "val"); cache.put(2, "val");
cache.put(3, "val"); cache.put(3, "val");
Expand Down
Expand Up @@ -38,14 +38,14 @@ public class GridCachePartitionedClientOnlyNoPrimaryFullApiSelfTest extends Grid
* *
*/ */
public void testMapKeysToNodes() { public void testMapKeysToNodes() {
cache().affinity().mapKeysToNodes(Arrays.asList("1", "2")); grid(0).affinity(null).mapKeysToNodes(Arrays.asList("1", "2"));
} }


/** /**
* *
*/ */
public void testMapKeyToNode() { public void testMapKeyToNode() {
assert cache().affinity().mapKeyToNode("1") == null; assert grid(0).affinity(null).mapKeyToNode("1") == null;
} }


/** /**
Expand Down

0 comments on commit 625b33f

Please sign in to comment.