use of org.apache.geode.internal.cache.DiskRegion in project geode by apache.
the class DiskRegionDUnitTest method testInvalidate.
/**
* Tests that once an overflowed entry is {@linkplain Region#invalidate invalidated} its value is
* gone.
*/
@Test
public void testInvalidate() 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() <= 10; total++) {
int[] array = new int[250];
array[0] = total;
region.put(new Integer(total), array);
}
region.invalidate(new Integer(0));
assertNull(region.get(new Integer(0)));
}
use of org.apache.geode.internal.cache.DiskRegion in project geode by apache.
the class TestDiskRegion method main1.
public static void main1(String[] args) throws Exception {
DistributedSystem system = DistributedSystem.connect(new java.util.Properties());
Cache cache = CacheFactory.create(system);
AttributesFactory factory = new AttributesFactory();
factory.setEvictionAttributes(EvictionAttributes.createLRUMemoryAttributes(2, (ObjectSizer) null, EvictionAction.OVERFLOW_TO_DISK));
factory.setCacheListener(new CacheListenerAdapter() {
public void afterUpdate(EntryEvent event) {
System.out.println("UPDATE: " + event.getKey() + " -> (" + event.getOldValue() + " -> " + event.getNewValue() + ")");
}
});
LocalRegion region = (LocalRegion) cache.createRegion("TestDiskRegion", factory.create());
DiskRegion dr = region.getDiskRegion();
DiskRegionStats diskStats = dr.getStats();
LRUStatistics lruStats = getLRUStats(region);
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Hit enter to perform action");
for (int i = 0; true; i++) {
br.readLine();
// Thread.sleep(500);
Object key = new Integer(i);
Object value = new byte[200000];
region.put(key, value);
System.out.println(key + " -> " + value + " evictions = " + lruStats.getEvictions() + ", writes = " + diskStats.getWrites());
}
}
use of org.apache.geode.internal.cache.DiskRegion in project geode by apache.
the class PersistentRecoveryOrderDUnitTest method testFinishIncompleteInitializationNoSend.
@Test
public void testFinishIncompleteInitializationNoSend() throws Exception {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
// Add a hook which will disconnect the DS before sending a prepare message
vm1.invoke(new SerializableRunnable() {
public void run() {
DistributionMessageObserver.setInstance(new DistributionMessageObserver() {
@Override
public void beforeSendMessage(DistributionManager dm, DistributionMessage message) {
if (message instanceof PrepareNewPersistentMemberMessage) {
DistributionMessageObserver.setInstance(null);
getSystem().disconnect();
}
}
@Override
public void afterProcessMessage(DistributionManager dm, DistributionMessage message) {
}
});
}
});
createPersistentRegion(vm0);
putAnEntry(vm0);
updateTheEntry(vm0);
try {
createPersistentRegion(vm1);
} catch (Exception e) {
if (!(e.getCause() instanceof DistributedSystemDisconnectedException)) {
throw e;
}
}
closeRegion(vm0);
// This wait for VM0 to come back
AsyncInvocation async1 = createPersistentRegionAsync(vm1);
waitForBlockedInitialization(vm1);
createPersistentRegion(vm0);
async1.getResult();
checkForEntry(vm1);
vm0.invoke(new SerializableRunnable("check for offline members") {
public void run() {
Cache cache = getCache();
DistributedRegion region = (DistributedRegion) cache.getRegion(REGION_NAME);
PersistentMembershipView view = region.getPersistenceAdvisor().getMembershipView();
DiskRegion dr = region.getDiskRegion();
assertEquals(Collections.emptySet(), dr.getOfflineMembers());
assertEquals(1, dr.getOnlineMembers().size());
}
});
}
use of org.apache.geode.internal.cache.DiskRegion in project geode by apache.
the class MemberMBeanBridge method addRegion.
public void addRegion(Region region) {
if (region.getAttributes().getPartitionAttributes() != null) {
addPartionRegionStats(((PartitionedRegion) region).getPrStats());
}
LocalRegion l = (LocalRegion) region;
if (l.getEvictionController() != null) {
LRUStatistics stats = l.getEvictionController().getLRUHelper().getStats();
if (stats != null) {
addLRUStats(stats);
}
}
DiskRegion dr = l.getDiskRegion();
if (dr != null) {
for (DirectoryHolder dh : dr.getDirectories()) {
addDirectoryStats(dh.getDiskDirectoryStats());
}
}
}
use of org.apache.geode.internal.cache.DiskRegion in project geode by apache.
the class MemberMBeanBridge method removeRegion.
public void removeRegion(Region region) {
if (region.getAttributes().getPartitionAttributes() != null) {
removePartionRegionStats(((PartitionedRegion) region).getPrStats());
}
LocalRegion l = (LocalRegion) region;
if (l.getEvictionController() != null) {
LRUStatistics stats = l.getEvictionController().getLRUHelper().getStats();
if (stats != null) {
removeLRUStats(stats);
}
}
DiskRegion dr = l.getDiskRegion();
if (dr != null) {
for (DirectoryHolder dh : dr.getDirectories()) {
removeDirectoryStats(dh.getDiskDirectoryStats());
}
}
}
Aggregations