use of org.apache.geode.management.internal.cli.dto.Value2 in project geode by apache.
the class GemfireDataCommandsDUnitTest method testRemoveJsonCommand.
@Test
public void testRemoveJsonCommand() {
final String keyPrefix = "testKey";
setupForGetPutRemoveLocateEntry("testRemoveJsonCommand");
final VM vm1 = Host.getHost(0).getVM(1);
final VM vm2 = Host.getHost(0).getVM(2);
SerializableRunnable putKeys = new SerializableRunnable() {
@Override
public void run() {
Cache cache = getCache();
Region region = cache.getRegion(DATA_REGION_NAME_PATH);
assertNotNull(region);
region.clear();
for (int i = 0; i < COUNT; i++) {
String keyString = keyPrefix + i;
Key1 key = new Key1();
key.setId(keyString);
key.setName("name" + keyString);
Value2 value2 = new Value2();
value2.setStateName("State" + keyString);
value2.setCapitalCity("capital" + keyString);
value2.setPopulation(i * 100);
value2.setAreaInSqKm(i * 100.4365);
region.put(key, value2);
}
}
};
vm1.invoke(putKeys);
for (int i = 0; i < COUNT; i++) {
String command = "remove";
String keyString = keyPrefix + i;
String keyJson = keyTemplate.replaceAll("\\?", keyString);
getLogWriter().info("Removing key with json key : " + keyJson);
command = command + " " + "--key=" + keyJson + " --region=" + DATA_REGION_NAME_PATH + " --key-class=" + Key1.class.getCanonicalName();
CommandResult cmdResult = executeCommand(command);
printCommandOutput(cmdResult);
assertEquals(Result.Status.OK, cmdResult.getStatus());
validateResult(cmdResult, true);
}
SerializableRunnable checkRemoveKeys = new SerializableRunnable() {
@Override
public void run() {
Cache cache = getCache();
Region region = cache.getRegion(DATA_REGION_NAME_PATH);
assertNotNull(region);
for (int i = 0; i < COUNT; i++) {
String keyString = keyPrefix + i;
Key1 key = new Key1();
key.setId(keyString);
key.setName("name" + keyString);
assertEquals(false, region.containsKey(key));
}
assertEquals(0, region.size());
}
};
vm1.invoke(checkRemoveKeys);
vm2.invoke(checkRemoveKeys);
}
use of org.apache.geode.management.internal.cli.dto.Value2 in project geode by apache.
the class GemfireDataCommandsDUnitTest method testGetLocateEntryJsonKeys.
// GEODE-1182: random ports, BindException, HeadlessGFSH,
@Category(FlakyTest.class)
// waitForCriterion, time sensitive
@Test
public void testGetLocateEntryJsonKeys() {
final String keyPrefix = "testKey";
setupForGetPutRemoveLocateEntry("testGetLocateEntryJsonKeys");
final VM vm1 = Host.getHost(0).getVM(1);
final VM vm2 = Host.getHost(0).getVM(2);
SerializableRunnable putKeys = new SerializableRunnable() {
@Override
public void run() {
Cache cache = getCache();
Region region = cache.getRegion(DATA_REGION_NAME_PATH);
assertNotNull(region);
region.clear();
for (int i = 0; i < COUNT; i++) {
String keyString = keyPrefix + i;
Key1 key = new Key1();
key.setId(keyString);
key.setName("name" + keyString);
Value2 value2 = new Value2();
value2.setStateName("State" + keyString);
value2.setCapitalCity("capital" + keyString);
value2.setPopulation(i * 100);
value2.setAreaInSqKm(i * 100.4365);
region.put(key, value2);
}
// Added for Bug #51175
List<String> colors = new ArrayList<String>();
colors.add("White");
colors.add("Red");
colors.add("Blue");
Map<String, String> attrMap = new HashMap<String, String>();
attrMap.put("power", "90hp");
attrMap.put("turningRadius", "4mtr");
attrMap.put("engineCapacity", "1248cc");
attrMap.put("turboGeometry", "VGT");
Set<String> attrSet = new HashSet<String>();
attrSet.add("power");
attrSet.add("turningRadius");
for (int i = COUNT; i < COUNT + 5; i++) {
String keyString = keyPrefix + i;
Key1 key = new Key1();
key.setId(keyString);
key.setName("name" + keyString);
Car car = new Car();
car.setMake("Make" + keyString);
car.setModel("Model" + keyString);
car.setColors(colors);
car.setAttributes(attrMap);
car.setAttributeSet(attrSet);
region.put(key, car);
}
}
};
String[] expectedCols = { "id", "name", "stateName", "capitalCity", "population", "areaInSqKm" };
vm1.invoke(putKeys);
for (int i = 0; i < COUNT; i++) {
String command = "get";
String keyString = keyPrefix + i;
String population = "" + i * 100;
String area = "" + i * (100.4365);
String keyJson = keyTemplate.replaceAll("\\?", keyString);
String valueJson = valueTemplate.replaceAll("\\?1", population);
valueJson = valueJson.replaceAll("\\?2", area);
valueJson = valueJson.replaceAll("\\?", keyString);
getLogWriter().info("Getting key with json key : " + keyJson);
command = command + " " + "--key=" + keyJson + " --region=" + DATA_REGION_NAME_PATH + " --key-class=" + Key1.class.getCanonicalName();
command = command + " --value-class=" + Value2.class.getCanonicalName();
CommandResult cmdResult = executeCommand(command);
printCommandOutput(cmdResult);
assertEquals(Result.Status.OK, cmdResult.getStatus());
validateResult(cmdResult, true);
validateJSONGetResult(cmdResult, expectedCols);
command = "locate entry";
command = command + " " + "--key=" + keyJson + " --region=" + DATA_REGION_NAME_PATH + " --key-class=" + Key1.class.getCanonicalName();
command = command + " --value-class=" + Value2.class.getCanonicalName();
cmdResult = executeCommand(command);
printCommandOutput(cmdResult);
assertEquals(Result.Status.OK, cmdResult.getStatus());
validateResult(cmdResult, true);
}
// Added for Bug #51175
expectedCols = new String[] { "id", "name", "attributes", "make", "model", "colors", "attributeSet" };
for (int i = COUNT; i < COUNT + 5; i++) {
String command = "get";
String keyString = keyPrefix + i;
String population = "" + i * 100;
String area = "" + i * (100.4365);
String keyJson = keyTemplate.replaceAll("\\?", keyString);
String valueJson = valueTemplate.replaceAll("\\?1", population);
valueJson = valueJson.replaceAll("\\?2", area);
valueJson = valueJson.replaceAll("\\?", keyString);
getLogWriter().info("Getting key with json key : " + keyJson);
command = command + " " + "--key=" + keyJson + " --region=" + DATA_REGION_NAME_PATH + " --key-class=" + Key1.class.getCanonicalName();
command = command + " --value-class=" + Value2.class.getCanonicalName();
CommandResult cmdResult = executeCommand(command);
printCommandOutput(cmdResult);
assertEquals(Result.Status.OK, cmdResult.getStatus());
validateResult(cmdResult, true);
// validateJSONGetResult(cmdResult, expectedCols);
validateJSONGetResultValues(cmdResult, expectedCols);
command = "locate entry";
command = command + " " + "--key=" + keyJson + " --region=" + DATA_REGION_NAME_PATH + " --key-class=" + Key1.class.getCanonicalName();
command = command + " --value-class=" + Value2.class.getCanonicalName();
cmdResult = executeCommand(command);
printCommandOutput(cmdResult);
assertEquals(Result.Status.OK, cmdResult.getStatus());
validateResult(cmdResult, true);
}
}
Aggregations