Skip to content

Commit

Permalink
IGNITE-96 Changed tests on client module to JCache API.
Browse files Browse the repository at this point in the history
  • Loading branch information
niktikhonov committed Feb 9, 2015
1 parent bf7d876 commit 7e9b0c1
Show file tree
Hide file tree
Showing 15 changed files with 294 additions and 279 deletions.
Expand Up @@ -18,15 +18,13 @@
package org.apache.ignite.client; package org.apache.ignite.client;


import org.apache.ignite.*; import org.apache.ignite.*;
import org.apache.ignite.cache.affinity.*;
import org.apache.ignite.client.balancer.*; import org.apache.ignite.client.balancer.*;
import org.apache.ignite.client.impl.*; import org.apache.ignite.client.impl.*;
import org.apache.ignite.client.ssl.*; import org.apache.ignite.client.ssl.*;
import org.apache.ignite.cluster.*; import org.apache.ignite.cluster.*;
import org.apache.ignite.compute.*; import org.apache.ignite.compute.*;
import org.apache.ignite.configuration.*; import org.apache.ignite.configuration.*;
import org.apache.ignite.internal.*; import org.apache.ignite.internal.*;
import org.apache.ignite.internal.processors.affinity.*;
import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.internal.util.typedef.*;
import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.internal.util.typedef.internal.*;
import org.apache.ignite.lang.*; import org.apache.ignite.lang.*;
Expand All @@ -46,7 +44,6 @@
import static org.apache.ignite.cache.CacheDistributionMode.*; import static org.apache.ignite.cache.CacheDistributionMode.*;
import static org.apache.ignite.cache.CacheMode.*; import static org.apache.ignite.cache.CacheMode.*;
import static org.apache.ignite.cache.CacheWriteSynchronizationMode.*; import static org.apache.ignite.cache.CacheWriteSynchronizationMode.*;
import static org.apache.ignite.testframework.GridTestUtils.*;


/** /**
* *
Expand Down Expand Up @@ -281,7 +278,7 @@ private void doTestSyncCommitFlag(final GridClientData data) throws Exception {
final String key = "k0"; final String key = "k0";


Collection<UUID> affNodesIds = F.viewReadOnly( Collection<UUID> affNodesIds = F.viewReadOnly(
grid(0).cache(data.cacheName()).affinity().mapKeyToPrimaryAndBackups(key), affinity(grid(0).jcache(data.cacheName())).mapKeyToPrimaryAndBackups(key),
F.node2id()); F.node2id());


final GridClientData dataFirst = data.pinNodes(F.first(client.compute().nodes())); final GridClientData dataFirst = data.pinNodes(F.first(client.compute().nodes()));
Expand Down Expand Up @@ -467,11 +464,11 @@ public void testMultithreadedCachePut() throws Exception {


ClusterNode node = ignite.cluster().mapKeyToNode(PARTITIONED_CACHE_NAME, key); ClusterNode node = ignite.cluster().mapKeyToNode(PARTITIONED_CACHE_NAME, key);


if (!puts.get(key).get2().equals(gridMap.get(node.id()).cache(PARTITIONED_CACHE_NAME).peek(key))) { if (!puts.get(key).get2().equals(gridMap.get(node.id()).jcache(PARTITIONED_CACHE_NAME).peek(key))) {
// printAffinityState(gridMap.values()); // printAffinityState(gridMap.values());


failNotEquals("Node don't have value for key [nodeId=" + node.id() + ", key=" + key + "]", failNotEquals("Node don't have value for key [nodeId=" + node.id() + ", key=" + key + "]",
puts.get(key).get2(), gridMap.get(node.id()).cache(PARTITIONED_CACHE_NAME).peek(key)); puts.get(key).get2(), gridMap.get(node.id()).jcache(PARTITIONED_CACHE_NAME).peek(key));
} }


// Assert that client has properly determined affinity node. // Assert that client has properly determined affinity node.
Expand All @@ -492,26 +489,11 @@ public void testMultithreadedCachePut() throws Exception {


// Check that no other nodes see this key. // Check that no other nodes see this key.
for (UUID id : F.view(gridMap.keySet(), F.notEqualTo(node.id()))) for (UUID id : F.view(gridMap.keySet(), F.notEqualTo(node.id())))
assertNull("Got value in near cache.", gridMap.get(id).cache(PARTITIONED_CACHE_NAME).peek(key)); assertNull("Got value in near cache.", gridMap.get(id).jcache(PARTITIONED_CACHE_NAME).peek(key));
} }


for (Ignite g : gridMap.values()) for (Ignite g : gridMap.values())
g.cache(PARTITIONED_CACHE_NAME).clear(); g.jcache(PARTITIONED_CACHE_NAME).clear();
}

/**
* @param grids Collection for Grids to print affinity info.
*/
private void printAffinityState(Iterable<Ignite> grids) {
for (Ignite g : grids) {
GridAffinityAssignmentCache affCache = getFieldValue(
((IgniteKernal)g).internalCache(PARTITIONED_CACHE_NAME).context().affinity(),
"aff");

CacheAffinityFunction aff = getFieldValue(affCache, "aff");

info("Affinity [nodeId=" + g.cluster().localNode().id() + ", affinity=" + aff + "]");
}
} }


/** {@inheritDoc} */ /** {@inheritDoc} */
Expand Down
Expand Up @@ -72,12 +72,12 @@ protected Boolean executeJob(Object arg) throws IgniteException {


String expAffKey = (String)it.next(); String expAffKey = (String)it.next();


Object affKey = ignite.cache(cacheName).affinity().affinityKey(obj); Object affKey = ignite.affinity(cacheName).affinityKey(obj);


if (!expAffKey.equals(affKey)) if (!expAffKey.equals(affKey))
throw new IgniteException("Unexpected affinity key: " + affKey); throw new IgniteException("Unexpected affinity key: " + affKey);


if (!ignite.cache(cacheName).affinity().mapKeyToNode(obj).isLocal()) if (!ignite.affinity(cacheName).mapKeyToNode(obj).isLocal())
throw new IgniteException("Job is not run on primary node."); throw new IgniteException("Job is not run on primary node.");


return true; return true;
Expand Down
Expand Up @@ -401,12 +401,12 @@ public void testAffinityExecute() throws Exception {
public void testInvalidateFlag() throws Exception { public void testInvalidateFlag() throws Exception {
IgniteEx g0 = grid(0); IgniteEx g0 = grid(0);


GridCache<String, String> cache = g0.cache(PARTITIONED_CACHE_NAME); IgniteCache<String, String> cache = g0.jcache(PARTITIONED_CACHE_NAME);


String key = null; String key = null;


for (int i = 0; i < 10_000; i++) { for (int i = 0; i < 10_000; i++) {
if (!cache.affinity().isPrimaryOrBackup(g0.localNode(), String.valueOf(i))) { if (!affinity(cache).isPrimaryOrBackup(g0.localNode(), String.valueOf(i))) {
key = String.valueOf(i); key = String.valueOf(i);


break; break;
Expand All @@ -424,9 +424,9 @@ public void testInvalidateFlag() throws Exception {
d.flagsOn(GridClientCacheFlag.INVALIDATE).put(key, "zzz"); d.flagsOn(GridClientCacheFlag.INVALIDATE).put(key, "zzz");


for (Ignite g : G.allGrids()) { for (Ignite g : G.allGrids()) {
cache = g.cache(PARTITIONED_CACHE_NAME); cache = g.jcache(PARTITIONED_CACHE_NAME);


if (cache.affinity().isPrimaryOrBackup(g.cluster().localNode(), key)) if (affinity(cache).isPrimaryOrBackup(g.cluster().localNode(), key))
assertEquals("zzz", cache.peek(key)); assertEquals("zzz", cache.peek(key));
else else
assertNull(cache.peek(key)); assertNull(cache.peek(key));
Expand Down Expand Up @@ -619,7 +619,7 @@ public void testAffinityPut() throws Exception {
partitioned.put(key, "val" + key); partitioned.put(key, "val" + key);


for (Map.Entry<UUID, Ignite> entry : gridsByLocNode.entrySet()) { for (Map.Entry<UUID, Ignite> entry : gridsByLocNode.entrySet()) {
Object val = entry.getValue().cache(PARTITIONED_CACHE_NAME).peek(key); Object val = entry.getValue().jcache(PARTITIONED_CACHE_NAME).peek(key);


if (primaryNodeId.equals(entry.getKey())) if (primaryNodeId.equals(entry.getKey()))
assertEquals("val" + key, val); assertEquals("val" + key, val);
Expand All @@ -641,7 +641,7 @@ public void testAffinityPut() throws Exception {
partitioned.pinNodes(node).put(pinnedKey, "val" + pinnedKey); partitioned.pinNodes(node).put(pinnedKey, "val" + pinnedKey);


for (Map.Entry<UUID, Ignite> entry : gridsByLocNode.entrySet()) { for (Map.Entry<UUID, Ignite> entry : gridsByLocNode.entrySet()) {
Object val = entry.getValue().cache(PARTITIONED_CACHE_NAME).peek(pinnedKey); Object val = entry.getValue().jcache(PARTITIONED_CACHE_NAME).peek(pinnedKey);


if (primaryNodeId.equals(entry.getKey()) || pinnedNodeId.equals(entry.getKey())) if (primaryNodeId.equals(entry.getKey()) || pinnedNodeId.equals(entry.getKey()))
assertEquals("val" + pinnedKey, val); assertEquals("val" + pinnedKey, val);
Expand Down

0 comments on commit 7e9b0c1

Please sign in to comment.