Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ISPN-3325 ConsistentHashV1IntegrationTest.testCorrectBalancingOfKeysAfterNodeKill random failures #1974

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -14,26 +14,26 @@
import org.infinispan.server.hotrod.HotRodServer;
import org.infinispan.test.MultipleCacheManagersTest;
import org.infinispan.test.TestingUtil;
import org.infinispan.commons.util.Util;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterTest;
import org.testng.annotations.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;

import static org.infinispan.client.hotrod.test.HotRodClientTestingUtil.*;
import static org.infinispan.client.hotrod.test.HotRodClientTestingUtil.killServers;
import static org.infinispan.server.hotrod.test.HotRodTestingUtil.hotRodCacheConfiguration;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertTrue;

/**
* @author Mircea Markus
*/
@Test (groups = "functional", testName = "client.hotrod.ConsistentHashV1IntegrationTest")
public class ConsistentHashV1IntegrationTest extends MultipleCacheManagersTest {
public static final int NUM_KEYS = 200;

private HotRodServer hotRodServer1;
private HotRodServer hotRodServer2;
Expand Down Expand Up @@ -117,23 +117,18 @@ public void testCorrectBalancingOfKeys() {
private void runTest(int cacheIndex) {
ConsistentHash serverCH = advancedCache(cacheIndex).getDistributionManager().getConsistentHash();

// compatibility with 1.0/1.1 clients is not perfect, so we must allow for some misses
int misses = 0;
for (int i = 0; i < 200; i++) {
for (int i = 0; i < NUM_KEYS; i++) {
byte[] keyBytes = (byte[]) kas.getKeyForAddress(address(cacheIndex));
String key = DistributionRetryTest.ByteKeyGenerator.getStringObject(keyBytes);
List<Address> serverBackups = serverCH.locateOwners(keyBytes);
assert serverBackups.contains(address(cacheIndex));
remoteCache.put(key, "v");

Address hitServer = getHitServer();
if (!serverBackups.contains(hitServer)) {
misses++;
}
Address serverPrimary = serverCH.locatePrimaryOwner(keyBytes);
assertEquals(address(cacheIndex), serverPrimary);

assert misses < 5 : String.format("i=%s, backups: %s, hit server: %s, key=%s", i, serverBackups, hitServer, Util.printArray(key.getBytes(), false));
remoteCache.put(key, "v");
}

// compatibility with 1.0/1.1 clients is not perfect, so we must allow for some misses
assertTrue(hitCountInterceptor(cacheIndex).getHits() > NUM_KEYS * 0.99);
hitCountInterceptor(cacheIndex).reset();
}

public void testCorrectBalancingOfKeysAfterNodeKill() {
Expand Down Expand Up @@ -189,27 +184,15 @@ private org.infinispan.client.hotrod.impl.consistenthash.ConsistentHash extractC
return transport.getConsistentHash();
}

private Address getHitServer() {
List<Address> result = new ArrayList<Address>();
private void resetHitInterceptors() {
for (int i = 0; i < 4; i++) {
InterceptorChain ic = advancedCache(i).getComponentRegistry().getComponent(InterceptorChain.class);
HitsAwareCacheManagersTest.HitCountInterceptor interceptor =
(HitsAwareCacheManagersTest.HitCountInterceptor) ic.getInterceptorsWithClass(HitsAwareCacheManagersTest.HitCountInterceptor.class).get(0);
if (interceptor.getHits() == 1) {
result.add(address(i));
}
HitsAwareCacheManagersTest.HitCountInterceptor interceptor = hitCountInterceptor(i);
interceptor.reset();
}
if (result.size() > 1) throw new IllegalStateException("More than one hit! : " + result);
return result.get(0);
}

private void resetHitInterceptors() {
for (int i = 0; i < 4; i++) {
InterceptorChain ic = advancedCache(i).getComponentRegistry().getComponent(InterceptorChain.class);
HitsAwareCacheManagersTest.HitCountInterceptor interceptor =
(HitsAwareCacheManagersTest.HitCountInterceptor) ic.getInterceptorsWithClass(HitsAwareCacheManagersTest.HitCountInterceptor.class).get(0);
interceptor.reset();
}
private HitsAwareCacheManagersTest.HitCountInterceptor hitCountInterceptor(int i) {
InterceptorChain ic = advancedCache(i).getComponentRegistry().getComponent(InterceptorChain.class);
return (HitsAwareCacheManagersTest.HitCountInterceptor) ic.getInterceptorsWithClass(HitsAwareCacheManagersTest.HitCountInterceptor.class).get(0);
}
}
2 changes: 0 additions & 2 deletions parent/pom.xml
Expand Up @@ -1864,7 +1864,6 @@
</execution>
</executions>
<configuration>
<scalaVersion>${version.scala}</scalaVersion>
<jvmArgs>
<jvmArg>-Xmx256m</jvmArg>
</jvmArgs>
Expand Down Expand Up @@ -1913,7 +1912,6 @@
</execution>
</executions>
<configuration>
<scalaVersion>${version.scala}</scalaVersion>
<jvmArgs>
<jvmArg>-Xmx256m</jvmArg>
<jvmArg>-XX:+UseCompressedOops</jvmArg>
Expand Down