Skip to content

Commit

Permalink
IGNITE-23997 Remove setForceServerMode from GridCacheAbstractFullApiS…
Browse files Browse the repository at this point in the history
…elfTest (#11746)
  • Loading branch information
nizhikov authored Dec 17, 2024
1 parent 08ebc23 commit 6b0f279
Show file tree
Hide file tree
Showing 16 changed files with 160 additions and 217 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.configuration.NearCacheConfiguration;
import org.apache.ignite.internal.IgniteEx;
import org.apache.ignite.internal.IgniteKernal;
import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException;
import org.apache.ignite.internal.util.lang.GridAbsPredicateX;
Expand Down Expand Up @@ -340,7 +341,14 @@ protected final boolean partitionedMode() {
*/
@SuppressWarnings({"unchecked"})
@Override protected IgniteCache<String, Integer> jcache() {
return jcache(0);
return defaultInstance().cache(DEFAULT_CACHE_NAME);
}

/**
* @return Default Ignite instance.
*/
public IgniteEx defaultInstance() {
return grid(0);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public class GridCacheAtomicClientOnlyMultiNodeFullApiSelfTest extends GridCache

long ttl = 500;

grid(0).cache(DEFAULT_CACHE_NAME).
defaultInstance().cache(DEFAULT_CACHE_NAME).
withExpiryPolicy(new TouchedExpiryPolicy(new Duration(MILLISECONDS, ttl))).put(key, 1);

boolean wait = waitForCondition(new GridAbsPredicate() {
Expand Down Expand Up @@ -303,7 +303,7 @@ public class GridCacheAtomicClientOnlyMultiNodeFullApiSelfTest extends GridCache

long ttl = 500;

grid(0).cache(DEFAULT_CACHE_NAME).
defaultInstance().cache(DEFAULT_CACHE_NAME).
withExpiryPolicy(new TouchedExpiryPolicy(new Duration(MILLISECONDS, ttl))).put(key, 1);

Thread.sleep(ttl + 100);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.Lock;
import javax.cache.expiry.Duration;
import javax.cache.expiry.ExpiryPolicy;
import javax.cache.expiry.TouchedExpiryPolicy;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.IgniteTransactions;
Expand All @@ -40,16 +40,19 @@
import org.apache.ignite.configuration.NearCacheConfiguration;
import org.apache.ignite.events.Event;
import org.apache.ignite.events.EventType;
import org.apache.ignite.internal.IgniteEx;
import org.apache.ignite.internal.processors.cache.GatewayProtectedCacheProxy;
import org.apache.ignite.internal.processors.cache.GridCacheEntryEx;
import org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException;
import org.apache.ignite.internal.processors.resource.GridSpringResourceContext;
import org.apache.ignite.internal.util.lang.GridAbsPredicateX;
import org.apache.ignite.internal.util.lang.IgnitePair;
import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.internal.util.typedef.P1;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.lang.IgnitePredicate;
import org.apache.ignite.testframework.GridTestUtils;
import org.apache.ignite.testframework.SupplierX;
import org.apache.ignite.transactions.Transaction;
import org.junit.Test;

Expand All @@ -61,16 +64,14 @@
*
*/
public class GridCacheNearOnlyMultiNodeFullApiSelfTest extends GridCachePartitionedMultiNodeFullApiSelfTest {
/** */
private static AtomicInteger cnt;

/** Index of the near-only instance. */
protected Integer nearIdx;

/** */
protected boolean isMultiJvm;

/** {@inheritDoc} */
@Override protected void beforeTestsStarted() throws Exception {
cnt = new AtomicInteger();

super.beforeTestsStarted();

for (int i = 0; i < gridCount(); i++) {
Expand All @@ -96,7 +97,7 @@ protected boolean clientHasNearCache() {
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);

if (cnt.getAndIncrement() == 0 || (cnt.get() > gridCount() && cnt.get() % gridCount() == 0)) {
if (igniteInstanceName.equals(getTestIgniteInstanceName(gridCount() - 1))) {
info("Use grid '" + igniteInstanceName + "' as near-only.");

cfg.setClientMode(true);
Expand All @@ -109,6 +110,61 @@ protected boolean clientHasNearCache() {
return cfg;
}

/** {@inheritDoc} */
@Override protected Ignite startGrid(String igniteInstanceName, GridSpringResourceContext ctx) throws Exception {
return sameJvmForClientNode(() -> super.startGrid(igniteInstanceName, ctx), igniteInstanceName);
}

/** */
public <R> R sameJvmForClientNode(SupplierX<R> s, String igniteInstanceName) {
boolean prevMultiJvm = isMultiJvm;

try {
if (isMultiJvm && getConfiguration(igniteInstanceName).isClientMode())
isMultiJvm = false;

return s.get();
}
catch (Exception e) {
throw new RuntimeException(e);
}
finally {
isMultiJvm = prevMultiJvm;
}
}

/** {@inheritDoc} */
@Override protected IgniteEx grid(int idx) {
return sameJvmForClientNode(() -> super.grid(idx), getTestIgniteInstanceName(idx));
}

/** {@inheritDoc} */
@Override protected IgniteEx ignite(int idx) {
return sameJvmForClientNode(() -> super.ignite(idx), getTestIgniteInstanceName(idx));
}

/** {@inheritDoc} */
@Override protected void stopGrid(String igniteInstanceName, boolean cancel, boolean awaitTop) {
sameJvmForClientNode(() -> {
super.stopGrid(igniteInstanceName, cancel, awaitTop);
return null;
}, igniteInstanceName);
}

/** {@inheritDoc} */
@Override public IgniteEx defaultInstance() {
IgniteEx cli = grid(gridCount() - 1);

assertTrue(cli.configuration().isClientMode());

return cli;
}

/** {@inheritDoc} */
@Override protected boolean isMultiJvm() {
return isMultiJvm;
}

/** {@inheritDoc} */
@Override protected CacheConfiguration cacheConfiguration(String igniteInstanceName) throws Exception {
CacheConfiguration cfg = super.cacheConfiguration(igniteInstanceName);
Expand Down Expand Up @@ -152,7 +208,7 @@ protected boolean clientHasNearCache() {
* @return A not near-only cache.
*/
@Override protected IgniteCache<String, Integer> fullCache() {
return nearIdx == 0 ? jcache(1) : jcache(0);
return nearIdx == (gridCount() - 1) ? jcache(1) : jcache();
}

/**
Expand Down Expand Up @@ -566,7 +622,7 @@ else if (i == nearIdx)
final CountDownLatch lockCnt = new CountDownLatch(1);
final CountDownLatch unlockCnt = new CountDownLatch(1);

grid(0).events().localListen(new IgnitePredicate<Event>() {
defaultInstance().events().localListen(new IgnitePredicate<Event>() {
@Override public boolean apply(Event evt) {
switch (evt.type()) {
case EVT_CACHE_OBJECT_LOCKED:
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class GridCachePartitionedFullApiSelfTest extends GridCacheAbstractFullAp
@Test
public void testUpdate() throws Exception {
if (gridCount() > 1) {
IgniteCache<Object, Object> cache = grid(0).cache(DEFAULT_CACHE_NAME);
IgniteCache<Object, Object> cache = defaultInstance().cache(DEFAULT_CACHE_NAME);

Integer key = nearKey(cache);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public class GridCachePartitionedMultiNodeFullApiSelfTest extends GridCacheParti
* @return Affinity nodes for this cache.
*/
public Collection<ClusterNode> affinityNodes() {
return grid(0).cluster().nodes();
return defaultInstance().cluster().nodes();
}

/**
Expand All @@ -81,7 +81,7 @@ public void testPutAllRemoveAll() throws Exception {
for (int i = 0; i < size; i++)
putMap.put(i, i * i);

IgniteCache<Object, Object> c0 = grid(0).cache(DEFAULT_CACHE_NAME);
IgniteCache<Object, Object> c0 = defaultInstance().cache(DEFAULT_CACHE_NAME);
IgniteCache<Object, Object> c1 = grid(1).cache(DEFAULT_CACHE_NAME);

c0.putAll(putMap);
Expand Down Expand Up @@ -109,7 +109,7 @@ public void testPutAllPutAll() throws Exception {
for (int i = 0; i < size; i++)
putMap.put(i, i);

IgniteCache<Object, Object> prj0 = grid(0).cache(DEFAULT_CACHE_NAME);
IgniteCache<Object, Object> prj0 = defaultInstance().cache(DEFAULT_CACHE_NAME);
IgniteCache<Object, Object> prj1 = grid(1).cache(DEFAULT_CACHE_NAME);

prj0.putAll(putMap);
Expand Down Expand Up @@ -144,7 +144,7 @@ public void testPutDebug() throws Exception {

final int size = 10;

IgniteCache<Object, Object> cache0 = grid(0).cache(DEFAULT_CACHE_NAME);
IgniteCache<Object, Object> cache0 = defaultInstance().cache(DEFAULT_CACHE_NAME);

for (int i = 0; i < size; i++) {
info("Putting value [i=" + i + ']');
Expand Down Expand Up @@ -283,8 +283,8 @@ else if (ignite1 == null)
for (int i = 0; i < 10_000 && keys.size() < 5; i++) {
String key = String.valueOf(i);

if (ignite(0).affinity(DEFAULT_CACHE_NAME).isPrimary(ignite0.localNode(), key) &&
ignite(0).affinity(DEFAULT_CACHE_NAME).isBackup(ignite1.localNode(), key)) {
if (defaultInstance().affinity(DEFAULT_CACHE_NAME).isPrimary(ignite0.localNode(), key) &&
defaultInstance().affinity(DEFAULT_CACHE_NAME).isBackup(ignite1.localNode(), key)) {
keys.add(key);

cache0.put(key, val++);
Expand Down Expand Up @@ -351,7 +351,7 @@ public void testAffinity() throws Exception {
if (!isMultiJvm())
info("All affinity nodes: " + affinityNodes());

IgniteCache<Object, Object> cache = grid(0).cache(DEFAULT_CACHE_NAME);
IgniteCache<Object, Object> cache = defaultInstance().cache(DEFAULT_CACHE_NAME);

info("Cache affinity nodes: " + affinity(cache).mapKeyToPrimaryAndBackups(key));

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
*/
public class GridCacheAtomicClientOnlyMultiJvmFullApiSelfTest extends
GridCacheAtomicClientOnlyMultiNodeFullApiSelfTest {
/** {@inheritDoc} */
@Override protected boolean isMultiJvm() {
return true;
/** */
public GridCacheAtomicClientOnlyMultiJvmFullApiSelfTest() {
isMultiJvm = true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
*/
public class GridCacheAtomicClientOnlyMultiJvmP2PDisabledFullApiSelfTest extends
GridCacheAtomicClientOnlyMultiNodeP2PDisabledFullApiSelfTest {
/** {@inheritDoc} */
@Override protected boolean isMultiJvm() {
return true;
/** */
public GridCacheAtomicClientOnlyMultiJvmP2PDisabledFullApiSelfTest() {
isMultiJvm = true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
*/
public class GridCacheAtomicNearOnlyMultiJvmFullApiSelfTest extends
GridCacheAtomicNearOnlyMultiNodeFullApiSelfTest {
/** {@inheritDoc} */
@Override protected boolean isMultiJvm() {
return true;
/** */
public GridCacheAtomicNearOnlyMultiJvmFullApiSelfTest() {
isMultiJvm = true;
}
}
Loading

0 comments on commit 6b0f279

Please sign in to comment.