Skip to content

Instantly share code, notes, and snippets.

@galderz
Created July 24, 2012 07:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save galderz/3168674 to your computer and use it in GitHub Desktop.
Save galderz/3168674 to your computer and use it in GitHub Desktop.
/*
* Copyright 2012 Red Hat, Inc. and/or its affiliates.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
package org.infinispan;
import org.infinispan.configuration.cache.CacheMode;
import org.infinispan.configuration.cache.ConfigurationBuilder;
import org.infinispan.manager.EmbeddedCacheManager;
import org.infinispan.test.MultipleCacheManagersTest;
import org.infinispan.test.TestingUtil;
import org.infinispan.test.fwk.TransportFlags;
import org.testng.annotations.Test;
import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertFalse;
/**
* // TODO: Document this
*
* @author Galder Zamarreño
* @since // TODO
*/
@Test(groups = "functional", testName = "RayTest")
public class SizeAccuracyTest extends MultipleCacheManagersTest {
ConfigurationBuilder builder;
@Override
protected void createCacheManagers() throws Throwable {
builder = getDefaultClusteredCacheConfig(CacheMode.DIST_SYNC, false);
createClusteredCaches(2, builder);
}
public void testSizeAfterEmptyingCacheTest() throws Exception {
Future<Void> node3Join = null, node4Join = null;
int batchSize = 100;
for (int i = 0; i < 1000; i++) {
cache(0).put("k" + i, "some data");
if (i % batchSize == 0) {
System.out.println("Adding " + i + " key/value pairs...");
}
if (i == 500) {
node3Join = fork(new Callable<Void>() {
@Override
public Void call() throws Exception {
EmbeddedCacheManager cm = addClusterEnabledCacheManager(builder,
new TransportFlags().withMerge(true));
cm.getCache();
return null;
}
});
node4Join = fork(new Callable<Void>() {
@Override
public Void call() throws Exception {
EmbeddedCacheManager cm = addClusterEnabledCacheManager(builder,
new TransportFlags().withMerge(true));
cm.getCache();
return null;
}
});
}
Thread.sleep(10);
}
if (node3Join == null) throw new Exception("Node 3 not joined");
node3Join.get();
if (node4Join == null) throw new Exception("Node 4 not joined");
node4Join.get();
TestingUtil.waitForRehashToComplete(cache(0), cache(1), cache(2), cache(3));
for (int i = 0; i < 1000; i++) {
cache(0).remove("k"+i);
if (i % batchSize == 0) {
System.out.println("Deleting " + i + " key/value pairs...");
}
Thread.sleep(10);
}
for (int i = 0; i < 1000; i++) {
assertFalse(cache(0).containsKey("k" + i));
}
assertEquals(0, cache(0).size());
assertEquals(0, cache(1).size());
assertEquals(0, cache(2).size());
assertEquals(0, cache(3).size());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment