Search in sources :

Example 1 with DistributedSystemConfig

use of org.apache.geode.admin.DistributedSystemConfig in project geode by apache.

the class ShutdownAllDUnitTest method shutDownAllMembers.

// TODO prpersist
// test move bucket
// test async put
// test create a new bucket by put async
private void shutDownAllMembers(VM vm, final int expnum) {
    vm.invoke(new SerializableRunnable("Shutdown all the members") {

        public void run() {
            DistributedSystemConfig config;
            AdminDistributedSystemImpl adminDS = null;
            try {
                config = AdminDistributedSystemFactory.defineDistributedSystem(getSystem(), "");
                adminDS = (AdminDistributedSystemImpl) AdminDistributedSystemFactory.getDistributedSystem(config);
                adminDS.connect();
                Set members = adminDS.shutDownAllMembers();
                int num = members == null ? 0 : members.size();
                assertEquals(expnum, num);
            } catch (AdminException e) {
                throw new RuntimeException(e);
            } finally {
                if (adminDS != null) {
                    adminDS.disconnect();
                }
            }
        }
    });
    // clean up for this vm
    System.setProperty("TestInternalGemFireError", "false");
}
Also used : AdminException(org.apache.geode.admin.AdminException) DistributedSystemConfig(org.apache.geode.admin.DistributedSystemConfig) TreeSet(java.util.TreeSet) Set(java.util.Set) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) AdminDistributedSystemImpl(org.apache.geode.admin.internal.AdminDistributedSystemImpl)

Example 2 with DistributedSystemConfig

use of org.apache.geode.admin.DistributedSystemConfig in project geode by apache.

the class PersistentPartitionedRegionTestBase method backup.

// used for above test
protected BackupStatus backup(VM vm) {
    return (BackupStatus) vm.invoke(new SerializableCallable("Backup all members") {

        public Object call() {
            DistributedSystemConfig config;
            AdminDistributedSystem adminDS = null;
            try {
                config = AdminDistributedSystemFactory.defineDistributedSystem(getSystem(), "");
                adminDS = AdminDistributedSystemFactory.getDistributedSystem(config);
                adminDS.connect();
                adminDS.waitToBeConnected(MAX_WAIT);
                return adminDS.backupAllMembers(getBackupDir());
            } catch (Exception e) {
                throw new RuntimeException(e);
            } finally {
                if (adminDS != null) {
                    adminDS.disconnect();
                }
            }
        }
    });
}
Also used : DistributedSystemConfig(org.apache.geode.admin.DistributedSystemConfig) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) AdminDistributedSystem(org.apache.geode.admin.AdminDistributedSystem) AdminException(org.apache.geode.admin.AdminException) ConflictingPersistentDataException(org.apache.geode.cache.persistence.ConflictingPersistentDataException) IOException(java.io.IOException) BackupStatus(org.apache.geode.admin.BackupStatus)

Example 3 with DistributedSystemConfig

use of org.apache.geode.admin.DistributedSystemConfig in project geode by apache.

the class DistributionManagerDUnitTest method createAlertListener.

static void createAlertListener() throws Exception {
    DistributedSystemConfig config = AdminDistributedSystemFactory.defineDistributedSystem(getSystemStatic(), null);
    adminSystem = AdminDistributedSystemFactory.getDistributedSystem(config);
    adminSystem.setAlertLevel(AlertLevel.SEVERE);
    adminSystem.addAlertListener(new AlertListener() {

        public void alert(Alert alert) {
            try {
                logger.info("alert listener invoked for alert originating in " + alert.getConnectionName());
                logger.info("  alert text = " + alert.getMessage());
                logger.info("  systemMember = " + alert.getSystemMember());
            } catch (Exception e) {
                logger.fatal("exception trying to use alert object", e);
            }
            synchronized (alertGuard) {
                alertReceived = true;
            }
        }
    });
    adminSystem.connect();
    assertTrue(adminSystem.waitToBeConnected(5 * 1000));
}
Also used : DistributedSystemConfig(org.apache.geode.admin.DistributedSystemConfig) Alert(org.apache.geode.admin.Alert) AlertListener(org.apache.geode.admin.AlertListener) UnknownHostException(java.net.UnknownHostException) IgnoredException(org.apache.geode.test.dunit.IgnoredException)

Example 4 with DistributedSystemConfig

use of org.apache.geode.admin.DistributedSystemConfig in project geode by apache.

the class PersistentRecoveryOrderDUnitTest method testCompactFromAdmin.

/**
   * Tests to make sure that we stop waiting for a member that we revoke.
   * 
   * @throws Exception
   */
@Test
public void testCompactFromAdmin() throws Exception {
    Host host = Host.getHost(0);
    final VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    createPersistentRegionWithoutCompaction(vm0);
    createPersistentRegionWithoutCompaction(vm1);
    vm1.invoke(new SerializableRunnable("Create some data") {

        public void run() {
            GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
            Region region = cache.getRegion(REGION_NAME);
            for (int i = 0; i < 1024; i++) {
                region.put(i, new byte[1024]);
            }
            for (int i = 2; i < 1024; i++) {
                assertTrue(region.destroy(i) != null);
            }
            DiskStore store = cache.findDiskStore(REGION_NAME);
            store.forceRoll();
        }
    });
    // vm1.invoke(new SerializableRunnable("compact") {
    // public void run() {
    // Cache cache = getCache();
    // DiskStore ds = cache.findDiskStore(REGION_NAME);
    // assertTrue(ds.forceCompaction());
    // }
    // });
    //
    // vm0.invoke(new SerializableRunnable("compact") {
    // public void run() {
    // Cache cache = getCache();
    // DiskStore ds = cache.findDiskStore(REGION_NAME);
    // assertTrue(ds.forceCompaction());
    // }
    // });
    vm2.invoke(new SerializableRunnable("Compact") {

        public void run() {
            GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
            DistributedSystemConfig config;
            AdminDistributedSystem adminDS = null;
            try {
                config = AdminDistributedSystemFactory.defineDistributedSystem(getSystem(), "");
                adminDS = AdminDistributedSystemFactory.getDistributedSystem(config);
                adminDS.connect();
                Map<DistributedMember, Set<PersistentID>> missingIds = adminDS.compactAllDiskStores();
                assertEquals(2, missingIds.size());
                for (Set<PersistentID> value : missingIds.values()) {
                    assertEquals(1, value.size());
                }
            } catch (AdminException e) {
                throw new RuntimeException(e);
            } finally {
                if (adminDS != null) {
                    adminDS.disconnect();
                }
            }
        }
    });
    SerializableRunnable compactVM = new SerializableRunnable("compact") {

        public void run() {
            Cache cache = getCache();
            DiskStore ds = cache.findDiskStore(REGION_NAME);
            assertFalse(ds.forceCompaction());
        }
    };
    vm0.invoke(compactVM);
    vm1.invoke(compactVM);
}
Also used : AdminException(org.apache.geode.admin.AdminException) Set(java.util.Set) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) AdminDistributedSystem(org.apache.geode.admin.AdminDistributedSystem) DiskStore(org.apache.geode.cache.DiskStore) DistributedSystemConfig(org.apache.geode.admin.DistributedSystemConfig) VM(org.apache.geode.test.dunit.VM) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) LocalRegion(org.apache.geode.internal.cache.LocalRegion) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) DiskRegion(org.apache.geode.internal.cache.DiskRegion) Region(org.apache.geode.cache.Region) Map(java.util.Map) HashMap(java.util.HashMap) PersistentID(org.apache.geode.cache.persistence.PersistentID) Cache(org.apache.geode.cache.Cache) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 5 with DistributedSystemConfig

use of org.apache.geode.admin.DistributedSystemConfig in project geode by apache.

the class IncrementalBackupDUnitTest method testMissingBaseline.

/**
   * Successful if all members perform a full backup when they share the baseline directory and it
   * is missing.
   */
@Test
public void testMissingBaseline() throws Exception {
    /*
     * Get the member ID for VM 1 and perform a baseline.
     */
    String memberId = getMemberId(Host.getHost(0).getVM(1));
    assertBackupStatus(performBaseline());
    /*
     * Find all of the member's oplogs in the baseline (*.crf,*.krf,*.drf)
     */
    Collection<File> memberBaselineOplogs = FileUtils.listFiles(getBackupDirForMember(getBaselineDir(), memberId), new RegexFileFilter(OPLOG_REGEX), DirectoryFileFilter.DIRECTORY);
    assertFalse(memberBaselineOplogs.isEmpty());
    List<String> memberBaselineOplogNames = new LinkedList<>();
    TransformUtils.transform(memberBaselineOplogs, memberBaselineOplogNames, TransformUtils.fileNameTransformer);
    /*
     * Custom incremental backup callable that retrieves the current baseline before deletion.
     */
    SerializableCallable callable = new SerializableCallable("Backup all members.") {

        private final File baselineDir = getBaselineBackupDir();

        @Override
        public Object call() {
            AdminDistributedSystem adminDS = null;
            try {
                DistributedSystemConfig config = AdminDistributedSystemFactory.defineDistributedSystem(getSystem(), "");
                adminDS = AdminDistributedSystemFactory.getDistributedSystem(config);
                adminDS.connect();
                return adminDS.backupAllMembers(getIncrementalDir(), this.baselineDir);
            } catch (AdminException e) {
                throw new RuntimeException(e);
            } finally {
                if (adminDS != null) {
                    adminDS.disconnect();
                }
            }
        }
    };
    /*
     * Do an incremental after deleting the baseline. It should discover that the baseline is gone
     * and backup all of the operation logs that are in the baseline.
     */
    FileUtils.deleteDirectory(getBaselineDir());
    Host.getHost(0).getVM(1).invoke(callable);
    /*
     * Find all of the member's oplogs in the incremental (*.crf,*.krf,*.drf)
     */
    Collection<File> memberIncrementalOplogs = FileUtils.listFiles(getBackupDirForMember(getIncrementalDir(), memberId), new RegexFileFilter(OPLOG_REGEX), DirectoryFileFilter.DIRECTORY);
    assertFalse(memberIncrementalOplogs.isEmpty());
    List<String> memberIncrementalOplogNames = new LinkedList<>();
    TransformUtils.transform(memberIncrementalOplogs, memberIncrementalOplogNames, TransformUtils.fileNameTransformer);
    /*
     * Assert that all of the baseline operation logs are in the incremental backup. If so, then the
     * missing baseline was discovered by the incremental backup process.
     */
    for (String oplog : memberBaselineOplogNames) {
        assertTrue(memberIncrementalOplogNames.contains(oplog));
    }
}
Also used : AdminException(org.apache.geode.admin.AdminException) DistributedSystemConfig(org.apache.geode.admin.DistributedSystemConfig) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) RegexFileFilter(org.apache.commons.io.filefilter.RegexFileFilter) File(java.io.File) LinkedList(java.util.LinkedList) AdminDistributedSystem(org.apache.geode.admin.AdminDistributedSystem) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Aggregations

DistributedSystemConfig (org.apache.geode.admin.DistributedSystemConfig)11 AdminException (org.apache.geode.admin.AdminException)10 AdminDistributedSystem (org.apache.geode.admin.AdminDistributedSystem)9 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)5 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)5 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)5 Test (org.junit.Test)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 Set (java.util.Set)4 BackupStatus (org.apache.geode.admin.BackupStatus)4 GemFireCacheImpl (org.apache.geode.internal.cache.GemFireCacheImpl)4 Host (org.apache.geode.test.dunit.Host)4 VM (org.apache.geode.test.dunit.VM)4 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)4 IOException (java.io.IOException)3 Cache (org.apache.geode.cache.Cache)3 Region (org.apache.geode.cache.Region)3 ConflictingPersistentDataException (org.apache.geode.cache.persistence.ConflictingPersistentDataException)3 PersistentID (org.apache.geode.cache.persistence.PersistentID)3