Search in sources :

Example 31 with PdxType

use of org.apache.geode.pdx.internal.PdxType in project geode by apache.

the class GFSnapshot method main.

public static void main(String[] args) throws Exception {
    if (args.length != 1) {
        System.out.println("Usage: GFSnapshot <file>");
        System.exit(1);
    }
    GFSnapshotImporter imp = new GFSnapshotImporter(new File(args[0]));
    try {
        System.out.println("Snapshot format is version " + imp.getVersion());
        System.out.println("Snapshot region is " + imp.getRegionName());
        ExportedRegistry reg = imp.getPdxTypes();
        Map<Integer, PdxType> types = reg.types();
        System.out.println("Found " + types.size() + " PDX types:");
        for (Entry<Integer, PdxType> entry : types.entrySet()) {
            System.out.println("\t" + entry.getKey() + " = " + entry.getValue());
        }
        Map<Integer, EnumInfo> enums = reg.enums();
        System.out.println("Found " + enums.size() + " PDX enums: ");
        for (Entry<Integer, EnumInfo> entry : enums.entrySet()) {
            System.out.println("\t" + entry.getKey() + " = " + entry.getValue());
        }
        System.out.println();
        SnapshotRecord record;
        while ((record = imp.readSnapshotRecord()) != null) {
            System.out.println(record.getKeyObject() + " = " + record.getValueObject());
        }
    } finally {
        imp.close();
    }
}
Also used : PdxType(org.apache.geode.pdx.internal.PdxType) EnumInfo(org.apache.geode.pdx.internal.EnumInfo) SnapshotRecord(org.apache.geode.internal.cache.snapshot.SnapshotPacket.SnapshotRecord) File(java.io.File)

Example 32 with PdxType

use of org.apache.geode.pdx.internal.PdxType in project geode by apache.

the class PdxRenameJUnitTest method testPdxRename.

@Test
public void testPdxRename() throws Exception {
    String DS_NAME = "PdxRenameJUnitTestDiskStore";
    Properties props = new Properties();
    props.setProperty(MCAST_PORT, "0");
    props.setProperty(LOCATORS, "");
    File f = new File(DS_NAME);
    f.mkdir();
    try {
        final Cache cache = (new CacheFactory(props)).setPdxPersistent(true).setPdxDiskStore(DS_NAME).create();
        try {
            DiskStoreFactory dsf = cache.createDiskStoreFactory();
            dsf.setDiskDirs(new File[] { f });
            dsf.create(DS_NAME);
            RegionFactory<String, PdxValue> rf1 = cache.createRegionFactory(RegionShortcut.LOCAL_PERSISTENT);
            rf1.setDiskStoreName(DS_NAME);
            Region<String, PdxValue> region1 = rf1.create("region1");
            region1.put("key1", new PdxValue(1));
            cache.close();
            Collection<Object> renameResults = DiskStoreImpl.pdxRename(DS_NAME, new File[] { f }, "apache", "pivotal");
            assertEquals(2, renameResults.size());
            for (Object o : renameResults) {
                if (o instanceof PdxType) {
                    PdxType t = (PdxType) o;
                    assertEquals("org.pivotal.geode.internal.PdxRenameJUnitTest$PdxValue", t.getClassName());
                } else {
                    EnumInfo ei = (EnumInfo) o;
                    assertEquals("org.pivotal.geode.internal.PdxRenameJUnitTest$Day", ei.getClassName());
                }
            }
            Collection<PdxType> types = DiskStoreImpl.getPdxTypes(DS_NAME, new File[] { f });
            assertEquals(1, types.size());
            assertEquals("org.pivotal.geode.internal.PdxRenameJUnitTest$PdxValue", types.iterator().next().getClassName());
        } finally {
            if (!cache.isClosed()) {
                cache.close();
            }
        }
    } finally {
        FileUtils.deleteDirectory(f);
    }
}
Also used : PdxType(org.apache.geode.pdx.internal.PdxType) EnumInfo(org.apache.geode.pdx.internal.EnumInfo) Properties(java.util.Properties) DiskStoreFactory(org.apache.geode.cache.DiskStoreFactory) CacheFactory(org.apache.geode.cache.CacheFactory) File(java.io.File) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

PdxType (org.apache.geode.pdx.internal.PdxType)32 Test (org.junit.Test)18 EnumInfo (org.apache.geode.pdx.internal.EnumInfo)14 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)11 TypeRegistry (org.apache.geode.pdx.internal.TypeRegistry)10 IOException (java.io.IOException)9 Cache (org.apache.geode.cache.Cache)9 CacheFactory (org.apache.geode.cache.CacheFactory)9 Region (org.apache.geode.cache.Region)8 SerializationTest (org.apache.geode.test.junit.categories.SerializationTest)8 File (java.io.File)7 Properties (java.util.Properties)6 InternalCache (org.apache.geode.internal.cache.InternalCache)6 Map (java.util.Map)5 DiskStoreFactory (org.apache.geode.cache.DiskStoreFactory)5 GemFireCacheImpl (org.apache.geode.internal.cache.GemFireCacheImpl)5 PdxInstance (org.apache.geode.pdx.PdxInstance)5 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)5 ArrayList (java.util.ArrayList)4 PdxInstanceImpl (org.apache.geode.pdx.internal.PdxInstanceImpl)4