use of org.apache.geode.cache.AttributesFactory in project geode by apache.
the class DiskRegionDUnitTest method testRegionEntryValues.
// testSwitchOut is no longer valid
// the test was not written correctly to recover
// and if it was it would now fail with a split brain
// testSwitchIn is no longer valid
// we no longer switchIn files if GII aborts.
/**
* Tests getting the {@linkplain org.apache.geode.cache.Region.Entry#getValue values} of region
* entries that have been overflowed.
*/
@Test
public void testRegionEntryValues() throws Exception {
final String name = this.getUniqueName();
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.LOCAL);
factory.setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(100, EvictionAction.OVERFLOW_TO_DISK));
File d = new File("DiskRegions" + OSProcess.getId());
d.mkdirs();
DiskStoreFactory dsf = getCache().createDiskStoreFactory();
dsf.setDiskDirs(new File[] { d });
DiskStore ds = dsf.create(name);
factory.setDiskStoreName(ds.getName());
Region region = createRegion(name, factory.create());
// DiskRegion dr = ((LocalRegion) region).getDiskRegion();
// DiskRegionStats diskStats = dr.getStats();
LRUStatistics lruStats = getLRUStats(region);
// Put in larger stuff until we start evicting
int total;
for (total = 0; lruStats.getEvictions() <= 0; total++) {
int[] array = new int[250];
array[0] = total;
region.put(new Integer(total), array);
}
// BitSet bits = new BitSet();
Set values = region.entrySet(false);
assertEquals(total, values.size());
for (Iterator iter = values.iterator(); iter.hasNext(); ) {
Region.Entry entry = (Region.Entry) iter.next();
Integer key = (Integer) entry.getKey();
int[] value = (int[]) entry.getValue();
assertNotNull(value);
assertEquals("Key/value" + key, key.intValue(), value[0]);
}
}
use of org.apache.geode.cache.AttributesFactory in project geode by apache.
the class ClearMultiVmCallBkDUnitTest method createCache.
public static void createCache() {
CacheListener aListener = new ListenerCallBk();
ds = (new ClearMultiVmCallBkDUnitTest()).getSystem(props);
cache = CacheFactory.create(ds);
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
// Set Cachelisterner : aListener
factory.setCacheListener(aListener);
RegionAttributes attr = factory.create();
region = cache.createRegion("map", attr);
}
use of org.apache.geode.cache.AttributesFactory in project geode by apache.
the class ClearMultiVmDUnitTest method testClearSimpleScenarios.
// test methods
@Test
public void testClearSimpleScenarios() {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
// verifying Single VM clear functionalities
vm0.invoke(new CacheSerializableRunnable("temp1") {
public void run2() throws CacheException {
region.put(new Integer(1), new String("first"));
region.put(new Integer(2), new String("second"));
region.put(new Integer(3), new String("third"));
region.clear();
assertEquals(0, region.size());
}
});
vm1.invoke(new CacheSerializableRunnable("temp1vm1") {
public void run2() throws CacheException {
assertEquals(0, region.size());
}
});
// verifying Single VM and single transaction clear functionalities
vm1.invoke(new CacheSerializableRunnable("temp2") {
public void run2() throws CacheException {
try {
region.put(new Integer(1), new String("first"));
region.put(new Integer(2), new String("second"));
region.put(new Integer(3), new String("third"));
cacheTxnMgr = cache.getCacheTransactionManager();
cacheTxnMgr.begin();
region.put(new Integer(4), new String("forth"));
try {
region.clear();
fail("expected exception not thrown");
} catch (UnsupportedOperationInTransactionException e) {
// expected
}
region.put(new Integer(5), new String("fifth"));
cacheTxnMgr.commit();
assertEquals(5, region.size());
assertEquals("fifth", region.get(new Integer(5)).toString());
} catch (CacheException ce) {
ce.printStackTrace();
} finally {
if (cacheTxnMgr.exists()) {
try {
cacheTxnMgr.commit();
} catch (Exception cce) {
cce.printStackTrace();
}
}
}
}
});
// verifying that region.clear does not clear the entries from sub region
vm0.invoke(new CacheSerializableRunnable("temp3") {
public void run2() throws CacheException {
region.put(new Integer(1), new String("first"));
region.put(new Integer(2), new String("second"));
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
RegionAttributes attr = factory.create();
Region subRegion = region.createSubregion("subr", attr);
subRegion.put(new Integer(3), new String("third"));
subRegion.put(new Integer(4), new String("forth"));
region.clear();
assertEquals(0, region.size());
assertEquals(2, subRegion.size());
}
});
}
use of org.apache.geode.cache.AttributesFactory in project geode by apache.
the class ClearMultiVmDUnitTest method testGiiandClear.
// end of testClearExceptions
@Test
public void testGiiandClear() throws Throwable {
if (false) {
getSystem().getLogWriter().severe("testGiiandClear skipped because of bug 34963");
} else {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
SerializableRunnable create = new CacheSerializableRunnable("create mirrored region") {
public void run2() throws CacheException {
AttributesFactory factory1 = new AttributesFactory();
factory1.setScope(Scope.DISTRIBUTED_ACK);
factory1.setDataPolicy(DataPolicy.REPLICATE);
RegionAttributes attr1 = factory1.create();
mirroredRegion = cache.createRegion("mirrored", attr1);
// reset slow
org.apache.geode.internal.cache.InitialImageOperation.slowImageProcessing = 0;
}
};
vm0.invoke(create);
vm0.invoke(new CacheSerializableRunnable("put initial data") {
public void run2() throws CacheException {
for (int i = 0; i < 1000; i++) {
mirroredRegion.put(new Integer(i), (new Integer(i)).toString());
}
}
});
// slow down image processing to make it more likely to get async updates
vm1.invoke(new SerializableRunnable("set slow image processing") {
public void run() {
// if this is a no_ack test, then we need to slow down more because of the
// pauses in the nonblocking operations
int pause = 50;
org.apache.geode.internal.cache.InitialImageOperation.slowImageProcessing = pause;
}
});
// now do the get initial image in vm1
AsyncInvocation async1 = vm1.invokeAsync(create);
// try to time a distributed clear to happen in the middle of gii
vm0.invoke(new SerializableRunnable("call clear when gii") {
public void run() {
try {
Thread.sleep(3 * 1000);
} catch (InterruptedException ex) {
fail("interrupted");
}
mirroredRegion.clear();
assertEquals(0, mirroredRegion.size());
}
});
ThreadUtils.join(async1, 30 * 1000);
if (async1.exceptionOccurred()) {
Assert.fail("async1 failed", async1.getException());
}
SerializableRunnable validate = new CacheSerializableRunnable("validate for region size") {
public void run2() throws CacheException {
assertEquals(0, mirroredRegion.size());
}
};
vm0.invoke(validate);
vm1.invoke(validate);
}
}
use of org.apache.geode.cache.AttributesFactory in project geode by apache.
the class DiskRegionDUnitTest method testRegionEvictValue.
/**
* Tests for region.evictValue().
*/
@Test
public void testRegionEvictValue() throws Exception {
final String name = this.getUniqueName() + "testRegionEvictValue";
File d = new File("DiskRegions" + OSProcess.getId());
d.mkdirs();
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.LOCAL);
factory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
// factory.setEvictionAttributes(EvictionAttributes.createLIFOEntryAttributes(capacity,
// EvictionAction.OVERFLOW_TO_DISK));
DiskStoreFactory dsf = getCache().createDiskStoreFactory();
dsf.setDiskDirs(new File[] { d });
DiskStore ds = dsf.create(name);
factory.setDiskStoreName(ds.getName());
Region region = createRegion(name, factory.create());
int size = 200;
for (int i = 0; i < size; i++) {
region.put("Key-" + i, new Integer(i));
}
// Evict alternate values.
for (int i = 0; i < size / 2; i++) {
if (i % 2 == 0) {
((LocalRegion) region).evictValue("Key-" + i);
}
}
// Check if its moved to disk.
for (int i = 0; i < size / 2; i++) {
if (i % 2 == 0) {
try {
Object value = ((LocalRegion) region).getValueInVM("Key-" + i);
if (value != null) {
fail("The values should have been evicted to disk, for key: " + "Key-" + i);
}
} catch (EntryNotFoundException e) {
fail("Entry not found not expected but occurred ");
}
}
}
}
Aggregations