Search in sources :

Example 1 with Value2

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);
}
Also used : Key1(org.apache.geode.management.internal.cli.dto.Key1) VM(org.apache.geode.test.dunit.VM) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Region(org.apache.geode.cache.Region) Value2(org.apache.geode.management.internal.cli.dto.Value2) Cache(org.apache.geode.cache.Cache) InternalCache(org.apache.geode.internal.cache.InternalCache) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 2 with Value2

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);
    }
}
Also used : HashMap(java.util.HashMap) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) ArrayList(java.util.ArrayList) Value2(org.apache.geode.management.internal.cli.dto.Value2) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) Key1(org.apache.geode.management.internal.cli.dto.Key1) Car(org.apache.geode.management.internal.cli.dto.Car) VM(org.apache.geode.test.dunit.VM) Region(org.apache.geode.cache.Region) Cache(org.apache.geode.cache.Cache) InternalCache(org.apache.geode.internal.cache.InternalCache) HashSet(java.util.HashSet) Category(org.junit.experimental.categories.Category) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Aggregations

Cache (org.apache.geode.cache.Cache)2 Region (org.apache.geode.cache.Region)2 InternalCache (org.apache.geode.internal.cache.InternalCache)2 Key1 (org.apache.geode.management.internal.cli.dto.Key1)2 Value2 (org.apache.geode.management.internal.cli.dto.Value2)2 CommandResult (org.apache.geode.management.internal.cli.result.CommandResult)2 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)2 VM (org.apache.geode.test.dunit.VM)2 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)2 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Car (org.apache.geode.management.internal.cli.dto.Car)1 Category (org.junit.experimental.categories.Category)1