Search in sources :

Example 36 with LocalRegion

use of org.apache.geode.internal.cache.LocalRegion 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());
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) DiskRegionStats(org.apache.geode.internal.cache.DiskRegionStats) ObjectSizer(org.apache.geode.cache.util.ObjectSizer) LocalRegion(org.apache.geode.internal.cache.LocalRegion) DistributedSystem(org.apache.geode.distributed.DistributedSystem) AttributesFactory(org.apache.geode.cache.AttributesFactory) DiskRegion(org.apache.geode.internal.cache.DiskRegion) CacheListenerAdapter(org.apache.geode.cache.util.CacheListenerAdapter) EntryEvent(org.apache.geode.cache.EntryEvent) LRUStatistics(org.apache.geode.internal.cache.lru.LRUStatistics) BufferedReader(java.io.BufferedReader) Cache(org.apache.geode.cache.Cache)

Example 37 with LocalRegion

use of org.apache.geode.internal.cache.LocalRegion in project geode by apache.

the class PRClientServerRegionFunctionExecutionFailoverDUnitTest method testOnRegionFailoverNonHASingleHop.

/*
   * Ensure that the while executing the function if the servers are down then the execution
   * shouldn't failover to other available server
   */
@Test
public void testOnRegionFailoverNonHASingleHop() throws InterruptedException {
    // See #47489
    // before enabling
    // it
    ArrayList commonAttributes = createCommonServerAttributes("TestPartitionedRegion", null, 0, 13, null);
    createClientServerScenarioSingleHop(commonAttributes, 20, 20, 20);
    server1.invoke(() -> PRClientServerRegionFunctionExecutionDUnitTest.createReplicatedRegion());
    server2.invoke(() -> PRClientServerRegionFunctionExecutionDUnitTest.createReplicatedRegion());
    server3.invoke(() -> PRClientServerRegionFunctionExecutionDUnitTest.createReplicatedRegion());
    client.invoke(() -> PRClientServerRegionFunctionExecutionDUnitTest.createProxyRegion(NetworkUtils.getServerHostName(server1.getHost())));
    // Make sure the buckets are created.
    client.invoke(new SerializableRunnable() {

        @Override
        public void run() {
            region = (LocalRegion) cache.getRegion(PRClientServerTestBase.PartitionedRegionName);
            for (int i = 0; i < 13; i++) {
                region.put(i, i);
            }
        }
    });
    // Make sure the client metadata is up to date.
    client.invoke(() -> PRClientServerRegionFunctionExecutionFailoverDUnitTest.fetchMetaData());
    Function function = new TestFunction(true, TestFunction.TEST_FUNCTION_NONHA_REGION);
    registerFunctionAtServer(function);
    final Function function2 = new TestFunction(true, TestFunction.TEST_FUNCTION_NONHA_NOP);
    registerFunctionAtServer(function);
    client.invoke(() -> PRClientServerRegionFunctionExecutionDUnitTest.regionSingleKeyExecutionNonHA(Boolean.FALSE, function, Boolean.FALSE));
    // This validation doesn't work because the client may
    // still be asynchronously recording the departure of the
    // failed server
    // System.err.println("Trying the second function");
    // //Make sure the client can now execute a function
    // //on the server
    // client.invoke(new SerializableRunnable() {
    // @Override
    // public void run() {
    // ResultCollector rs = FunctionService.onRegion(region).execute(function2);
    // rs.getResult();
    // }
    // });
    client.invoke(() -> PRClientServerRegionFunctionExecutionDUnitTest.verifyMetaData(new Integer(1), new Integer(0)));
}
Also used : Function(org.apache.geode.cache.execute.Function) TestFunction(org.apache.geode.internal.cache.functions.TestFunction) TestFunction(org.apache.geode.internal.cache.functions.TestFunction) ArrayList(java.util.ArrayList) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) LocalRegion(org.apache.geode.internal.cache.LocalRegion) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 38 with LocalRegion

use of org.apache.geode.internal.cache.LocalRegion in project geode by apache.

the class HAClearDUnitTest method destroyRegionFromServer.

// function to perform destroyRegion operation from server.
private CacheSerializableRunnable destroyRegionFromServer() {
    CacheSerializableRunnable clearFromServer = new CacheSerializableRunnable("destroyRegionFromServer") {

        public void run2() {
            LocalRegion region = (LocalRegion) cache.getRegion(Region.SEPARATOR + REGION_NAME);
            assertNotNull(region);
            region.destroyRegion();
        }
    };
    return clearFromServer;
}
Also used : CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) LocalRegion(org.apache.geode.internal.cache.LocalRegion)

Example 39 with LocalRegion

use of org.apache.geode.internal.cache.LocalRegion in project geode by apache.

the class HAClearDUnitTest method destroyRegion.

// function to perform destroyRegion operation from client.
private void destroyRegion() {
    LocalRegion region = (LocalRegion) cache.getRegion(Region.SEPARATOR + REGION_NAME);
    assertNotNull(region);
    region.destroyRegion();
}
Also used : LocalRegion(org.apache.geode.internal.cache.LocalRegion)

Example 40 with LocalRegion

use of org.apache.geode.internal.cache.LocalRegion in project geode by apache.

the class HAClearDUnitTest method clearRegion.

// function to perform clear operation from client.
private void clearRegion() {
    LocalRegion region = (LocalRegion) cache.getRegion(Region.SEPARATOR + REGION_NAME);
    assertNotNull(region);
    region.clear();
}
Also used : LocalRegion(org.apache.geode.internal.cache.LocalRegion)

Aggregations

LocalRegion (org.apache.geode.internal.cache.LocalRegion)243 Test (org.junit.Test)103 Region (org.apache.geode.cache.Region)70 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)54 IOException (java.io.IOException)50 AttributesFactory (org.apache.geode.cache.AttributesFactory)42 VM (org.apache.geode.test.dunit.VM)39 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)38 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)37 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)34 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)34 Cache (org.apache.geode.cache.Cache)31 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)31 Host (org.apache.geode.test.dunit.Host)31 Iterator (java.util.Iterator)29 QueryService (org.apache.geode.cache.query.QueryService)29 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)27 CancelException (org.apache.geode.CancelException)26 CacheException (org.apache.geode.cache.CacheException)26 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)25