Search in sources :

Example 46 with DiskStoreFactory

use of org.apache.geode.cache.DiskStoreFactory in project geode by apache.

the class DiskManagementDUnitTest method createPersistentRegionAsync.

private AsyncInvocation createPersistentRegionAsync(final VM memberVM) {
    return memberVM.invokeAsync("createPersistentRegionAsync", () -> {
        File dir = new File(diskDir, String.valueOf(ProcessUtils.identifyPid()));
        Cache cache = this.managementTestRule.getCache();
        DiskStoreFactory diskStoreFactory = cache.createDiskStoreFactory();
        diskStoreFactory.setDiskDirs(new File[] { dir });
        diskStoreFactory.setMaxOplogSize(1);
        diskStoreFactory.setAllowForceCompaction(true);
        diskStoreFactory.setAutoCompact(false);
        DiskStore diskStore = diskStoreFactory.create(REGION_NAME);
        RegionFactory regionFactory = cache.createRegionFactory();
        regionFactory.setDiskStoreName(diskStore.getName());
        regionFactory.setDiskSynchronous(true);
        regionFactory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
        regionFactory.setScope(Scope.DISTRIBUTED_ACK);
        regionFactory.create(REGION_NAME);
    });
}
Also used : DiskStore(org.apache.geode.cache.DiskStore) RegionFactory(org.apache.geode.cache.RegionFactory) File(java.io.File) DiskStoreFactory(org.apache.geode.cache.DiskStoreFactory) Cache(org.apache.geode.cache.Cache)

Example 47 with DiskStoreFactory

use of org.apache.geode.cache.DiskStoreFactory in project geode by apache.

the class DiskManagementDUnitTest method invokeForceCompaction.

/**
   * Invokes force compaction on disk store by MBean interface
   */
private void invokeForceCompaction(final VM memberVM) {
    memberVM.invoke("invokeForceCompaction", () -> {
        Cache cache = this.managementTestRule.getCache();
        DiskStoreFactory dsf = cache.createDiskStoreFactory();
        dsf.setAllowForceCompaction(true);
        String name = "testForceCompaction_" + ProcessUtils.identifyPid();
        DiskStore diskStore = dsf.create(name);
        ManagementService service = this.managementTestRule.getManagementService();
        DiskStoreMXBean diskStoreMXBean = service.getLocalDiskStoreMBean(name);
        assertThat(diskStoreMXBean).isNotNull();
        assertThat(diskStoreMXBean.getName()).isEqualTo(diskStore.getName());
        assertThat(diskStoreMXBean.forceCompaction()).isFalse();
    });
}
Also used : DiskStore(org.apache.geode.cache.DiskStore) SystemManagementService(org.apache.geode.management.internal.SystemManagementService) DiskStoreFactory(org.apache.geode.cache.DiskStoreFactory) Cache(org.apache.geode.cache.Cache)

Example 48 with DiskStoreFactory

use of org.apache.geode.cache.DiskStoreFactory in project geode by apache.

the class DiskManagementDUnitTest method invokeForceRoll.

/**
   * Invokes force roll on disk store by MBean interface
   */
private void invokeForceRoll(final VM memberVM) {
    memberVM.invoke("invokeForceRoll", () -> {
        Cache cache = this.managementTestRule.getCache();
        DiskStoreFactory diskStoreFactory = cache.createDiskStoreFactory();
        String name = "testForceRoll_" + ProcessUtils.identifyPid();
        DiskStore diskStore = diskStoreFactory.create(name);
        ManagementService service = this.managementTestRule.getManagementService();
        DiskStoreMXBean diskStoreMXBean = service.getLocalDiskStoreMBean(name);
        assertThat(diskStoreMXBean).isNotNull();
        assertThat(diskStoreMXBean.getName()).isEqualTo(diskStore.getName());
        diskStoreMXBean.forceRoll();
    });
}
Also used : DiskStore(org.apache.geode.cache.DiskStore) SystemManagementService(org.apache.geode.management.internal.SystemManagementService) DiskStoreFactory(org.apache.geode.cache.DiskStoreFactory) Cache(org.apache.geode.cache.Cache)

Example 49 with DiskStoreFactory

use of org.apache.geode.cache.DiskStoreFactory in project geode by apache.

the class IndexCommandsDUnitTest method createRepRegWithPersistence.

private Region<?, ?> createRepRegWithPersistence(String regionName, String diskStoreName, String diskDirName) {
    Cache cache = getCache();
    File diskStoreDirFile = new File(diskDirName);
    diskStoreDirFile.deleteOnExit();
    if (!diskStoreDirFile.exists()) {
        diskStoreDirFile.mkdirs();
    }
    DiskStoreFactory diskStoreFactory = cache.createDiskStoreFactory();
    diskStoreFactory.setDiskDirs(new File[] { diskStoreDirFile });
    diskStoreFactory.setMaxOplogSize(1);
    diskStoreFactory.setAllowForceCompaction(true);
    diskStoreFactory.setAutoCompact(false);
    diskStoreFactory.create(diskStoreName);
    /****
     * Eviction Attributes
     */
    EvictionAttributes ea = EvictionAttributes.createLRUEntryAttributes(1, EvictionAction.OVERFLOW_TO_DISK);
    RegionFactory regionFactory = cache.createRegionFactory();
    regionFactory.setDiskStoreName(diskStoreName);
    regionFactory.setDiskSynchronous(true);
    regionFactory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
    regionFactory.setEvictionAttributes(ea);
    return regionFactory.create(regionName);
}
Also used : EvictionAttributes(org.apache.geode.cache.EvictionAttributes) RegionFactory(org.apache.geode.cache.RegionFactory) File(java.io.File) DiskStoreFactory(org.apache.geode.cache.DiskStoreFactory) Cache(org.apache.geode.cache.Cache)

Example 50 with DiskStoreFactory

use of org.apache.geode.cache.DiskStoreFactory in project geode by apache.

the class PdxSerializableJUnitTest method testPdxPersistentKeys.

// for bugs 44271 and 44914
@Test
public void testPdxPersistentKeys() throws Exception {
    this.c.close();
    this.c = (GemFireCacheImpl) new CacheFactory().set(MCAST_PORT, "0").setPdxPersistent(true).setPdxDiskStore("pdxDS").create();
    try {
        DiskStoreFactory dsf = this.c.createDiskStoreFactory();
        dsf.create("pdxDS");
        this.c.createDiskStoreFactory().create("r2DS");
        Region r1 = this.c.createRegionFactory(RegionShortcut.LOCAL_PERSISTENT).create("r1");
        r1.put(new SimpleClass(1, (byte) 1), "1");
        r1.put(new SimpleClass(2, (byte) 2), "2");
        // so we have something to compact offline
        r1.put(new SimpleClass(1, (byte) 1), "1.2");
        Region r2 = this.c.createRegionFactory(RegionShortcut.LOCAL_PERSISTENT).setDiskStoreName("r2DS").create("r2");
        r2.put(new SimpleClass(1, (byte) 1), new SimpleClass(1, (byte) 1));
        r2.put(new SimpleClass(2, (byte) 2), new SimpleClass(2, (byte) 2));
        this.c.close();
        this.c = (GemFireCacheImpl) new CacheFactory().set(MCAST_PORT, "0").setPdxPersistent(true).setPdxDiskStore("pdxDS").create();
        dsf = this.c.createDiskStoreFactory();
        dsf.create("pdxDS");
        this.c.createDiskStoreFactory().create("r2DS");
        r1 = this.c.createRegionFactory(RegionShortcut.LOCAL_PERSISTENT).create("r1");
        r2 = this.c.createRegionFactory(RegionShortcut.LOCAL_PERSISTENT).setDiskStoreName("r2DS").create("r2");
        assertEquals(true, r1.containsKey(new SimpleClass(1, (byte) 1)));
        assertEquals(true, r1.containsKey(new SimpleClass(2, (byte) 2)));
        assertEquals(true, r2.containsKey(new SimpleClass(1, (byte) 1)));
        assertEquals(true, r2.containsKey(new SimpleClass(2, (byte) 2)));
        assertEquals(new SimpleClass(1, (byte) 1), r2.get(new SimpleClass(1, (byte) 1)));
        assertEquals(new SimpleClass(2, (byte) 2), r2.get(new SimpleClass(2, (byte) 2)));
        this.c.close();
        // use a cache.xml to recover
        this.c = (GemFireCacheImpl) new CacheFactory().set(MCAST_PORT, "0").create();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PrintWriter pw = new PrintWriter(new OutputStreamWriter(baos), true);
        pw.println("<?xml version=\"1.0\"?>");
        pw.println("<!DOCTYPE cache PUBLIC");
        pw.println("  \"-//GemStone Systems, Inc.//GemFire Declarative Caching 7.0//EN\"");
        pw.println("  \"http://www.gemstone.com/dtd/cache7_0.dtd\">");
        pw.println("<cache>");
        pw.println("  <disk-store name=\"r2DS\"/>");
        pw.println("  <disk-store name=\"pdxDS\"/>");
        pw.println("  <pdx persistent=\"true\" disk-store-name=\"pdxDS\"/>");
        pw.println("  <region name=\"r1\" refid=\"LOCAL_PERSISTENT\"/>");
        pw.println("  <region name=\"r2\" refid=\"LOCAL_PERSISTENT\">");
        pw.println("    <region-attributes disk-store-name=\"r2DS\"/>");
        pw.println("  </region>");
        pw.println("</cache>");
        pw.close();
        byte[] bytes = baos.toByteArray();
        this.c.loadCacheXml(new ByteArrayInputStream(bytes));
        r1 = this.c.getRegion("/r1");
        r2 = this.c.getRegion("/r2");
        assertEquals(true, r1.containsKey(new SimpleClass(1, (byte) 1)));
        assertEquals(true, r1.containsKey(new SimpleClass(2, (byte) 2)));
        assertEquals(true, r2.containsKey(new SimpleClass(1, (byte) 1)));
        assertEquals(true, r2.containsKey(new SimpleClass(2, (byte) 2)));
        assertEquals(new SimpleClass(1, (byte) 1), r2.get(new SimpleClass(1, (byte) 1)));
        assertEquals(new SimpleClass(2, (byte) 2), r2.get(new SimpleClass(2, (byte) 2)));
        this.c.close();
        // make sure offlines tools work with disk store that has pdx keys
        SystemAdmin.validateDiskStore("DEFAULT", ".");
        SystemAdmin.compactDiskStore("DEFAULT", ".");
        SystemAdmin.modifyDiskStore("DEFAULT", ".");
        SystemAdmin.validateDiskStore("r2DS", ".");
        SystemAdmin.compactDiskStore("r2DS", ".");
        SystemAdmin.modifyDiskStore("r2DS", ".");
        SystemAdmin.validateDiskStore("pdxDS", ".");
        SystemAdmin.compactDiskStore("pdxDS", ".");
        SystemAdmin.modifyDiskStore("pdxDS", ".");
    } finally {
        try {
            this.c.close();
        } finally {
            Pattern pattern = Pattern.compile("BACKUP(DEFAULT|pdxDS|r2DS).*");
            File[] files = new File(".").listFiles((dir1, name) -> pattern.matcher(name).matches());
            if (files != null) {
                for (File file : files) {
                    Files.delete(file.toPath());
                }
            }
        }
    }
}
Also used : Pattern(java.util.regex.Pattern) ByteArrayInputStream(java.io.ByteArrayInputStream) Region(org.apache.geode.cache.Region) OutputStreamWriter(java.io.OutputStreamWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CacheFactory(org.apache.geode.cache.CacheFactory) File(java.io.File) DiskStoreFactory(org.apache.geode.cache.DiskStoreFactory) PrintWriter(java.io.PrintWriter) SerializationTest(org.apache.geode.test.junit.categories.SerializationTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

DiskStoreFactory (org.apache.geode.cache.DiskStoreFactory)132 File (java.io.File)95 DiskStore (org.apache.geode.cache.DiskStore)91 Test (org.junit.Test)86 AttributesFactory (org.apache.geode.cache.AttributesFactory)56 Region (org.apache.geode.cache.Region)46 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)46 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)35 Cache (org.apache.geode.cache.Cache)32 LocalRegion (org.apache.geode.internal.cache.LocalRegion)24 RegionFactory (org.apache.geode.cache.RegionFactory)22 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)21 DiskRegion (org.apache.geode.internal.cache.DiskRegion)19 Properties (java.util.Properties)18 VM (org.apache.geode.test.dunit.VM)18 LRUStatistics (org.apache.geode.internal.cache.lru.LRUStatistics)16 GatewaySenderFactory (org.apache.geode.cache.wan.GatewaySenderFactory)12 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)11 IOException (java.io.IOException)10 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)10