Search in sources :

Example 6 with UninterruptibleFileChannel

use of org.apache.geode.internal.cache.persistence.UninterruptibleFileChannel in project geode by apache.

the class DiskRegionJUnitTest method testBridgeServerStoppingInSynchPersistOnlyForIOExceptionCase.

/**
   * If IOException occurs while updating an entry in an already initialized DiskRegion ,then the
   * bridge servers should not be stopped , if any running as they are no clients connected to it.
   */
@Test
public void testBridgeServerStoppingInSynchPersistOnlyForIOExceptionCase() throws Exception {
    DiskRegionProperties props = new DiskRegionProperties();
    props.setRegionName("IGNORE_EXCEPTION_testBridgeServerStoppingInSynchPersistOnlyForIOExceptionCase");
    props.setOverflow(true);
    props.setRolling(true);
    props.setDiskDirs(dirs);
    props.setPersistBackup(true);
    region = DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, props, Scope.LOCAL);
    CacheServer bs1 = cache.addCacheServer();
    bs1.setPort(0);
    bs1.start();
    region.create("key1", new byte[16]);
    region.create("key2", new byte[16]);
    // Get the oplog handle & hence the underlying file & close it
    UninterruptibleFileChannel oplogFileChannel = ((LocalRegion) region).getDiskRegion().testHook_getChild().getFileChannel();
    oplogFileChannel.close();
    try {
        region.put("key2", new byte[16]);
    } catch (DiskAccessException dae) {
    // OK expected
    }
    ((LocalRegion) region).getDiskStore().waitForClose();
    assertTrue(cache.isClosed());
    region = null;
    List bsRunning = cache.getCacheServers();
    // [anil & bruce] the following assertion was changed to true because
    // a disk access exception in a server should always stop the server
    assertTrue(bsRunning.isEmpty());
}
Also used : UninterruptibleFileChannel(org.apache.geode.internal.cache.persistence.UninterruptibleFileChannel) DiskAccessException(org.apache.geode.cache.DiskAccessException) CacheServer(org.apache.geode.cache.server.CacheServer) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 7 with UninterruptibleFileChannel

use of org.apache.geode.internal.cache.persistence.UninterruptibleFileChannel in project geode by apache.

the class DiskRegionJUnitTest method testBridgeServerRunningInSynchPersistOnlyForIOExceptionCase.

/**
   * If IOException occurs while initializing a region ,then the bridge servers should not be
   * stopped
   */
@Test
public void testBridgeServerRunningInSynchPersistOnlyForIOExceptionCase() throws Exception {
    DiskRegionProperties props = new DiskRegionProperties();
    props.setRegionName("IGNORE_EXCEPTION_testBridgeServerStoppingInSynchPersistOnlyForIOExceptionCase");
    props.setOverflow(true);
    props.setRolling(true);
    props.setDiskDirs(dirs);
    props.setPersistBackup(true);
    // just needs to be bigger than 65550
    props.setMaxOplogSize(100000);
    region = DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, props, Scope.LOCAL);
    CacheServer bs1 = cache.addCacheServer();
    bs1.setPort(0);
    bs1.start();
    region.create("key1", new byte[16]);
    region.create("key2", new byte[16]);
    // Get the oplog file path
    UninterruptibleFileChannel oplogFileChnl = ((LocalRegion) region).getDiskRegion().testHook_getChild().getFileChannel();
    // corrupt the opfile
    oplogFileChnl.position(2);
    ByteBuffer bf = ByteBuffer.allocate(416);
    for (int i = 0; i < 5; ++i) {
        bf.putInt(i);
    }
    bf.flip();
    // Corrupt the oplogFile
    oplogFileChnl.write(bf);
    // Close the region
    region.close();
    assertTrue(region.isDestroyed());
    try {
        region = DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, props, Scope.LOCAL);
        fail("expected DiskAccessException");
    } catch (DiskAccessException dae) {
    // OK expected
    }
    assertTrue(region.isDestroyed());
    region = null;
    List bsRunning = cache.getCacheServers();
    assertTrue(!bsRunning.isEmpty());
}
Also used : UninterruptibleFileChannel(org.apache.geode.internal.cache.persistence.UninterruptibleFileChannel) DiskAccessException(org.apache.geode.cache.DiskAccessException) CacheServer(org.apache.geode.cache.server.CacheServer) ArrayList(java.util.ArrayList) List(java.util.List) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 8 with UninterruptibleFileChannel

use of org.apache.geode.internal.cache.persistence.UninterruptibleFileChannel in project geode by apache.

the class Bug39079DUnitTest method validateRunningBridgeServerList.

private void validateRunningBridgeServerList() throws IOException {
    Region region = getCache().getRegion(REGION_NAME_testBridgeServerStoppingInSynchPersistOnlyForIOExceptionCase);
    try {
        region.create("key1", new byte[16]);
        region.create("key2", new byte[16]);
        // Get the oplog handle & hence the underlying file & close it
        UninterruptibleFileChannel oplogFileChannel = ((LocalRegion) region).getDiskRegion().testHook_getChild().getFileChannel();
        try {
            oplogFileChannel.close();
            region.put("key2", new byte[16]);
            fail("Expected DiskAccessException");
        } catch (DiskAccessException expected) {
        }
        ((LocalRegion) region).getDiskStore().waitForClose();
        assertTrue(region.getRegionService().isClosed());
        region = null;
        List bsRunning = getCache().getCacheServers();
        assertTrue(bsRunning.isEmpty());
    } finally {
        if (region != null) {
            region.destroyRegion();
        }
    }
}
Also used : UninterruptibleFileChannel(org.apache.geode.internal.cache.persistence.UninterruptibleFileChannel) DiskAccessException(org.apache.geode.cache.DiskAccessException) Region(org.apache.geode.cache.Region) List(java.util.List)

Aggregations

UninterruptibleFileChannel (org.apache.geode.internal.cache.persistence.UninterruptibleFileChannel)8 DiskAccessException (org.apache.geode.cache.DiskAccessException)6 List (java.util.List)3 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 CacheServer (org.apache.geode.cache.server.CacheServer)2 ByteBuffer (java.nio.ByteBuffer)1 Region (org.apache.geode.cache.Region)1 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)1