use of org.junit.experimental.categories.Category in project geode by apache.
the class PartitionedRegionDelayedRecoveryDUnitTest method testStartupDelay.
// GEODE-757: time sensitive, fails because event occurs 2 millis too
@Category(FlakyTest.class)
// thread unsafe test hook
@Test
public void testStartupDelay() {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
VM vm2 = host.getVM(2);
SerializableRunnable createPrRegions = new SerializableRunnable("createRegions") {
public void run() {
Cache cache = getCache();
InternalResourceManager.setResourceObserver(new MyResourceObserver());
AttributesFactory attr = new AttributesFactory();
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setStartupRecoveryDelay(5000);
paf.setRedundantCopies(1);
PartitionAttributes prAttr = paf.create();
attr.setPartitionAttributes(prAttr);
cache.createRegion("region1", attr.create());
}
};
// create the region in 2 VMS
vm0.invoke(createPrRegions);
vm1.invoke(createPrRegions);
// Do 1 put, which should create 1 bucket
vm0.invoke(new SerializableRunnable("putData") {
public void run() {
Cache cache = getCache();
PartitionedRegion region1 = (PartitionedRegion) cache.getRegion("region1");
region1.put(Integer.valueOf(1), "B");
region1.put(Integer.valueOf(2), "B");
region1.put(Integer.valueOf(3), "B");
region1.put(Integer.valueOf(4), "B");
}
});
// close 1 cache, which should make the bucket drop below
// the expected redundancy level.
vm1.invoke(new SerializableRunnable("close cache") {
public void run() {
Cache cache = getCache();
cache.close();
}
});
final long begin = System.currentTimeMillis();
// create the region in a third VM, which won't have any buckets
vm2.invoke(createPrRegions);
long elapsed = System.currentTimeMillis() - begin;
assertTrue("Create region should not have waited to recover redundancy. Elapsed=" + elapsed, elapsed < 5000);
// wait for the bucket to be copied
elapsed = waitForBucketRecovery(vm2, 4, begin);
assertTrue("Did not wait at least 5 seconds to create the bucket. Elapsed=" + elapsed, elapsed >= 5000);
vm2.invoke(new SerializableCallable("wait for primary move") {
public Object call() throws Exception {
Cache cache = getCache();
MyResourceObserver observer = (MyResourceObserver) InternalResourceManager.getResourceObserver();
observer.waitForRecovery(30, TimeUnit.SECONDS);
PartitionedRegion region1 = (PartitionedRegion) cache.getRegion("region1");
assertEquals(2, region1.getDataStore().getNumberOfPrimaryBucketsManaged());
return null;
}
});
}
use of org.junit.experimental.categories.Category in project geode by apache.
the class PartitionedRegionDelayedRecoveryDUnitTest method testDelay.
// GEODE-860: time sensitive, thread unsafe test hook, CountDownLatch,
@Category(FlakyTest.class)
// InterruptedException
@Test
public void testDelay() {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
VM vm2 = host.getVM(2);
SerializableRunnable createPrRegions = new SerializableRunnable("createRegions") {
public void run() {
final CountDownLatch rebalancingFinished = new CountDownLatch(1);
InternalResourceManager.setResourceObserver(new ResourceObserverAdapter() {
@Override
public void rebalancingOrRecoveryFinished(Region region) {
rebalancingFinished.countDown();
}
});
try {
Cache cache = getCache();
AttributesFactory attr = new AttributesFactory();
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setRecoveryDelay(5000);
paf.setRedundantCopies(1);
PartitionAttributes prAttr = paf.create();
attr.setPartitionAttributes(prAttr);
cache.createRegion("region1", attr.create());
if (!rebalancingFinished.await(60000, TimeUnit.MILLISECONDS)) {
fail("Redundancy recovery did not happen within 60 seconds");
}
} catch (InterruptedException e) {
Assert.fail("interrupted", e);
} finally {
InternalResourceManager.setResourceObserver(null);
}
}
};
// create the region in 2 VMS
vm0.invoke(createPrRegions);
vm1.invoke(createPrRegions);
// Do 1 put, which should create 1 bucket
vm0.invoke(new SerializableRunnable("putData") {
public void run() {
Cache cache = getCache();
PartitionedRegion region1 = (PartitionedRegion) cache.getRegion("region1");
region1.put("A", "B");
}
});
// create the region in a third VM, which won't have any buckets
vm2.invoke(createPrRegions);
final long begin = System.currentTimeMillis();
// close 1 cache, which should make the bucket drop below
// the expected redundancy level.
vm1.invoke(new SerializableRunnable("close cache") {
public void run() {
Cache cache = getCache();
cache.close();
}
});
long elapsed = waitForBucketRecovery(vm2, 1, begin);
assertTrue("Did not wait at least 5 seconds to create the bucket. Elapsed=" + elapsed, elapsed >= 5000);
}
use of org.junit.experimental.categories.Category in project geode by apache.
the class FixedPartitioningDUnitTest method testPut_ValidateDataOnMember_PrimarySecondary_Datastore.
/**
* This tests validate that datastore member does the put on itself as well as other datastores as
* per primary and secondary FixedPartitionAttributes defined on datastores.
*/
// GEODE-1704
@Category(FlakyTest.class)
@Test
public void testPut_ValidateDataOnMember_PrimarySecondary_Datastore() {
member1.invoke(() -> FixedPartitioningTestBase.createCacheOnMember());
FixedPartitionAttributes fpa1 = FixedPartitionAttributes.createFixedPartition(Quarter1, true, 3);
FixedPartitionAttributes fpa2 = FixedPartitionAttributes.createFixedPartition(Quarter2, false, 3);
List<FixedPartitionAttributes> fpaList = new ArrayList<FixedPartitionAttributes>();
fpaList.add(fpa1);
fpaList.add(fpa2);
member1.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Quarter", fpaList, 1, 40, 12, new QuarterPartitionResolver(), null, false));
member2.invoke(() -> FixedPartitioningTestBase.createCacheOnMember());
fpa1 = FixedPartitionAttributes.createFixedPartition(Quarter2, true, 3);
fpa2 = FixedPartitionAttributes.createFixedPartition(Quarter3, false, 3);
fpaList.clear();
fpaList.add(fpa1);
fpaList.add(fpa2);
member2.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Quarter", fpaList, 1, 40, 12, new QuarterPartitionResolver(), null, false));
member3.invoke(() -> FixedPartitioningTestBase.createCacheOnMember());
fpa1 = FixedPartitionAttributes.createFixedPartition(Quarter3, true, 3);
fpa2 = FixedPartitionAttributes.createFixedPartition(Quarter4, false, 3);
fpaList.clear();
fpaList.add(fpa1);
fpaList.add(fpa2);
member3.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Quarter", fpaList, 1, 40, 12, new QuarterPartitionResolver(), null, false));
member4.invoke(() -> FixedPartitioningTestBase.createCacheOnMember());
fpa1 = FixedPartitionAttributes.createFixedPartition(Quarter4, true, 3);
fpa2 = FixedPartitionAttributes.createFixedPartition(Quarter1, false, 3);
fpaList.clear();
fpaList.add(fpa1);
fpaList.add(fpa2);
member4.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Quarter", fpaList, 1, 40, 12, new QuarterPartitionResolver(), null, false));
member1.invoke(() -> FixedPartitioningTestBase.putThroughDataStore("Quarter"));
member1.invoke(() -> FixedPartitioningTestBase.checkPrimarySecondaryData(Quarter1, false));
member2.invoke(() -> FixedPartitioningTestBase.checkPrimarySecondaryData(Quarter2, false));
member3.invoke(() -> FixedPartitioningTestBase.checkPrimarySecondaryData(Quarter3, false));
member4.invoke(() -> FixedPartitioningTestBase.checkPrimarySecondaryData(Quarter4, false));
member1.invoke(() -> FixedPartitioningTestBase.checkPrimaryBucketsForQuarter(6, 3));
member2.invoke(() -> FixedPartitioningTestBase.checkPrimaryBucketsForQuarter(6, 3));
member3.invoke(() -> FixedPartitioningTestBase.checkPrimaryBucketsForQuarter(6, 3));
member4.invoke(() -> FixedPartitioningTestBase.checkPrimaryBucketsForQuarter(6, 3));
}
use of org.junit.experimental.categories.Category in project geode by apache.
the class DiskStoreCommandsDUnitTest method testMissingDiskStore.
// GEODE-2102
@Category(FlakyTest.class)
@Test
public void testMissingDiskStore() {
final String regionName = "testShowMissingDiskStoreRegion";
setUpJmxManagerOnVm0ThenConnect(null);
final VM vm0 = Host.getHost(0).getVM(0);
final VM vm1 = Host.getHost(0).getVM(1);
final String vm1Name = "VM" + vm1.getPid();
final String diskStoreName = "DiskStoreCommandsDUnitTest";
// Default setup creates a cache in the Manager, now create a cache in VM1
vm1.invoke(new SerializableRunnable() {
public void run() {
Properties localProps = new Properties();
localProps.setProperty(NAME, vm1Name);
getSystem(localProps);
Cache cache = getCache();
}
});
// Create a disk store and region in the Manager (VM0) and VM1 VMs
for (final VM vm : (new VM[] { vm0, vm1 })) {
final String vmName = "VM" + vm.getPid();
vm.invoke(new SerializableRunnable() {
public void run() {
Cache cache = getCache();
File diskStoreDirFile = new File(diskStoreName + vm.getPid());
diskStoreDirFile.mkdirs();
DiskStoreFactory diskStoreFactory = cache.createDiskStoreFactory();
diskStoreFactory.setDiskDirs(new File[] { diskStoreDirFile });
diskStoreFactory.setMaxOplogSize(1);
diskStoreFactory.setAllowForceCompaction(true);
diskStoreFactory.setAutoCompact(false);
diskStoreFactory.create(regionName);
RegionFactory regionFactory = cache.createRegionFactory();
regionFactory.setDiskStoreName(regionName);
regionFactory.setDiskSynchronous(true);
regionFactory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
regionFactory.setScope(Scope.DISTRIBUTED_ACK);
regionFactory.create(regionName);
}
});
}
// Add data to the region
vm0.invoke(new SerializableRunnable() {
public void run() {
Cache cache = getCache();
Region region = cache.getRegion(regionName);
region.put("A", "B");
}
});
// Make sure that everything thus far is okay and there are no missing disk stores
CommandResult cmdResult = executeCommand(CliStrings.SHOW_MISSING_DISK_STORE);
assertEquals(Result.Status.OK, cmdResult.getStatus());
assertTrue(commandResultToString(cmdResult).contains("No missing disk store found"));
// Close the region in the Manager (VM0) VM
vm0.invoke(new SerializableRunnable() {
public void run() {
Cache cache = getCache();
Region region = cache.getRegion(regionName);
region.close();
}
});
// Add data to VM1 and then close the region
vm1.invoke(new SerializableRunnable() {
public void run() {
Cache cache = getCache();
Region region = cache.getRegion(regionName);
region.put("A", "C");
region.close();
}
});
// Add the region back to the Manager (VM0) VM
vm0.invokeAsync(new SerializableRunnable() {
public void run() {
Cache cache = getCache();
RegionFactory regionFactory = cache.createRegionFactory();
regionFactory.setDiskStoreName(regionName);
regionFactory.setDiskSynchronous(true);
regionFactory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
regionFactory.setScope(Scope.DISTRIBUTED_ACK);
try {
regionFactory.create(regionName);
} catch (DistributedSystemDisconnectedException ignore) {
// okay to ignore
}
}
});
// Wait for the region in the Manager (VM0) to come online
vm0.invoke(new SerializableRunnable() {
public void run() {
WaitCriterion waitCriterion = new WaitCriterion() {
public boolean done() {
Cache cache = getCache();
PersistentMemberManager memberManager = ((InternalCache) cache).getPersistentMemberManager();
return !memberManager.getWaitingRegions().isEmpty();
}
public String description() {
return "Waiting for another persistent member to come online";
}
};
waitForCriterion(waitCriterion, 70000, 100, true);
}
});
// Validate that there is a missing disk store on VM1
cmdResult = executeCommand(CliStrings.SHOW_MISSING_DISK_STORE);
assertEquals(Result.Status.OK, cmdResult.getStatus());
String stringResult = commandResultToString(cmdResult);
System.out.println("command result=" + stringResult);
assertEquals(5, countLinesInString(stringResult, false));
assertTrue(stringContainsLine(stringResult, "Disk Store ID.*Host.*Directory"));
assertTrue(stringContainsLine(stringResult, ".*" + diskStoreName + vm1.getPid()));
// Extract the id from the returned missing disk store
String line = getLineFromString(stringResult, 4);
assertFalse(line.contains("---------"));
StringTokenizer resultTokenizer = new StringTokenizer(line);
String id = resultTokenizer.nextToken();
// Remove the missing disk store and validate the result
cmdResult = executeCommand("revoke missing-disk-store --id=" + id);
assertNotNull(cmdResult);
assertEquals(Result.Status.OK, cmdResult.getStatus());
assertTrue(commandResultToString(cmdResult).contains("Missing disk store successfully revoked"));
// Do our own cleanup so that the disk store directories can be removed
super.destroyDefaultSetup();
for (final VM vm : (new VM[] { vm0, vm1 })) {
final String vmName = "VM" + vm.getPid();
vm.invoke(new SerializableRunnable() {
public void run() {
try {
FileUtils.deleteDirectory((new File(diskStoreName + vm.getPid())));
} catch (IOException iex) {
// There's nothing else we can do
}
}
});
}
}
use of org.junit.experimental.categories.Category in project geode by apache.
the class DiskStoreCommandsDUnitTest method testCreateDiskStore.
// GEODE-1206: random ports, BindException
@Category(FlakyTest.class)
@Test
public void testCreateDiskStore() {
final String diskStore1Name = "testCreateDiskStore1";
final String diskStore2Name = "testCreateDiskStore2";
Properties localProps = new Properties();
localProps.setProperty(GROUPS, "Group0");
setUpJmxManagerOnVm0ThenConnect(localProps);
CommandResult cmdResult = executeCommand(CliStrings.LIST_DISK_STORE);
assertEquals(Result.Status.OK, cmdResult.getStatus());
assertTrue(commandResultToString(cmdResult).contains("No Disk Stores Found"));
final VM vm1 = Host.getHost(0).getVM(1);
final String vm1Name = "VM" + vm1.getPid();
final File diskStore1Dir1 = new File(new File(".").getAbsolutePath(), diskStore1Name + ".1");
this.filesToBeDeleted.add(diskStore1Dir1.getAbsolutePath());
final File diskStore1Dir2 = new File(new File(".").getAbsolutePath(), diskStore1Name + ".2");
this.filesToBeDeleted.add(diskStore1Dir2.getAbsolutePath());
vm1.invoke(new SerializableRunnable() {
public void run() {
diskStore1Dir1.mkdirs();
diskStore1Dir2.mkdirs();
Properties localProps = new Properties();
localProps.setProperty(NAME, vm1Name);
localProps.setProperty(GROUPS, "Group1");
getSystem(localProps);
getCache();
}
});
final VM vm2 = Host.getHost(0).getVM(2);
final String vm2Name = "VM" + vm2.getPid();
final File diskStore2Dir = new File(new File(".").getAbsolutePath(), diskStore2Name);
this.filesToBeDeleted.add(diskStore2Dir.getAbsolutePath());
vm2.invoke(new SerializableRunnable() {
public void run() {
diskStore2Dir.mkdirs();
Properties localProps = new Properties();
localProps.setProperty(NAME, vm2Name);
localProps.setProperty(GROUPS, "Group2");
getSystem(localProps);
getCache();
}
});
CommandStringBuilder commandStringBuilder = new CommandStringBuilder(CliStrings.CREATE_DISK_STORE);
commandStringBuilder.addOption(CliStrings.CREATE_DISK_STORE__NAME, diskStore1Name);
commandStringBuilder.addOption(CliStrings.CREATE_DISK_STORE__GROUP, "Group1");
commandStringBuilder.addOption(CliStrings.CREATE_DISK_STORE__ALLOW_FORCE_COMPACTION, "true");
commandStringBuilder.addOption(CliStrings.CREATE_DISK_STORE__AUTO_COMPACT, "false");
commandStringBuilder.addOption(CliStrings.CREATE_DISK_STORE__COMPACTION_THRESHOLD, "67");
commandStringBuilder.addOption(CliStrings.CREATE_DISK_STORE__MAX_OPLOG_SIZE, "355");
commandStringBuilder.addOption(CliStrings.CREATE_DISK_STORE__QUEUE_SIZE, "5321");
commandStringBuilder.addOption(CliStrings.CREATE_DISK_STORE__TIME_INTERVAL, "2023");
commandStringBuilder.addOption(CliStrings.CREATE_DISK_STORE__WRITE_BUFFER_SIZE, "3110");
commandStringBuilder.addOption(CliStrings.CREATE_DISK_STORE__DIRECTORY_AND_SIZE, diskStore1Dir1.getAbsolutePath() + "#1452637463," + diskStore1Dir2.getAbsolutePath());
cmdResult = executeCommand(commandStringBuilder.toString());
assertEquals(Result.Status.OK, cmdResult.getStatus());
String stringResult = commandResultToString(cmdResult);
assertEquals(3, countLinesInString(stringResult, false));
assertEquals(false, stringResult.contains("ERROR"));
assertTrue(stringContainsLine(stringResult, vm1Name + ".*Success"));
// Verify that the disk store was created on the correct member
cmdResult = executeCommand(CliStrings.LIST_DISK_STORE);
assertEquals(Result.Status.OK, cmdResult.getStatus());
stringResult = commandResultToString(cmdResult);
assertEquals(3, countLinesInString(stringResult, false));
assertTrue(stringContainsLine(stringResult, vm1Name + ".*" + diskStore1Name + " .*"));
assertFalse(stringContainsLine(stringResult, vm2Name + ".*" + diskStore1Name + " .*"));
// Verify that the disk store files were created in the correct directory.
assertEquals(diskStore1Dir1.listFiles().length, 2);
// Verify that all of the attributes of the disk store were set correctly.
commandStringBuilder = new CommandStringBuilder(CliStrings.DESCRIBE_DISK_STORE);
commandStringBuilder.addOption(CliStrings.DESCRIBE_DISK_STORE__MEMBER, vm1Name);
commandStringBuilder.addOption(CliStrings.DESCRIBE_DISK_STORE__NAME, diskStore1Name);
cmdResult = executeCommand(commandStringBuilder.toString());
assertEquals(Result.Status.OK, cmdResult.getStatus());
stringResult = commandResultToString(cmdResult);
assertTrue(stringContainsLine(stringResult, "Allow Force Compaction.*Yes"));
assertTrue(stringContainsLine(stringResult, "Auto Compaction.*No"));
assertTrue(stringContainsLine(stringResult, "Compaction Threshold.*67"));
assertTrue(stringContainsLine(stringResult, "Max Oplog Size.*355"));
assertTrue(stringContainsLine(stringResult, "Queue Size.*5321"));
assertTrue(stringContainsLine(stringResult, "Time Interval.*2023"));
assertTrue(stringContainsLine(stringResult, "Write Buffer Size.*3110"));
assertTrue(stringContainsLine(stringResult, ".*" + diskStore1Name + ".1 .*1452637463"));
assertTrue(stringContainsLine(stringResult, ".*" + diskStore1Name + ".2 .*" + Integer.MAX_VALUE));
commandStringBuilder = new CommandStringBuilder(CliStrings.CREATE_DISK_STORE);
commandStringBuilder.addOption(CliStrings.CREATE_DISK_STORE__NAME, diskStore2Name);
commandStringBuilder.addOption(CliStrings.CREATE_DISK_STORE__GROUP, "Group2");
commandStringBuilder.addOption(CliStrings.CREATE_DISK_STORE__DIRECTORY_AND_SIZE, diskStore2Dir.getAbsolutePath());
cmdResult = executeCommand(commandStringBuilder.toString());
assertEquals(Result.Status.OK, cmdResult.getStatus());
stringResult = commandResultToString(cmdResult);
assertEquals(3, countLinesInString(stringResult, false));
assertTrue(stringContainsLine(stringResult, vm2Name + ".*Success"));
// Verify that the second disk store was created correctly.
cmdResult = executeCommand(CliStrings.LIST_DISK_STORE);
assertEquals(Result.Status.OK, cmdResult.getStatus());
stringResult = commandResultToString(cmdResult);
assertEquals(4, countLinesInString(stringResult, false));
assertTrue(stringContainsLine(stringResult, vm1Name + ".*" + diskStore1Name + " .*"));
assertFalse(stringContainsLine(stringResult, vm2Name + ".*" + diskStore1Name + " .*"));
assertFalse(stringContainsLine(stringResult, vm1Name + ".*" + diskStore2Name + " .*"));
assertTrue(stringContainsLine(stringResult, vm2Name + ".*" + diskStore2Name + " .*"));
}
Aggregations