Search in sources :

Example 1 with Key1

use of org.apache.geode.management.internal.cli.dto.Key1 in project geode by apache.

the class GemfireDataCommandsDUnitTest method testPutJsonKeys.

// GEODE-1430
@Category(FlakyTest.class)
@Test
public void testPutJsonKeys() {
    final String keyPrefix = "testKey";
    setupForGetPutRemoveLocateEntry("testPutJsonKeys");
    final VM vm1 = Host.getHost(0).getVM(1);
    final VM vm2 = Host.getHost(0).getVM(2);
    for (int i = 0; i < COUNT; i++) {
        String command = "put";
        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("Putting key with json key : " + keyJson);
        getLogWriter().info("Putting key with json valye : " + valueJson);
        command = command + " " + "--key=" + keyJson + " --value=" + valueJson + " --region=" + DATA_REGION_NAME_PATH;
        command = command + " --key-class=" + Key1.class.getCanonicalName() + " --value-class=" + Value2.class.getCanonicalName();
        CommandResult cmdResult = executeCommand(command);
        printCommandOutput(cmdResult);
        assertEquals(Result.Status.OK, cmdResult.getStatus());
        validateResult(cmdResult, true);
    }
    // Bug #51175
    for (int i = COUNT; i < COUNT + 5; i++) {
        String command = "put";
        String keyString = keyPrefix + i;
        String id = "" + i * 100;
        String make = "" + i * (100.4365);
        String model = "" + i * (100.4365);
        String list = "['red','white','blue']";
        String set = "['red','white','blue']";
        String map = "{'power':'90hp'}";
        String keyJson = keyTemplate.replaceAll("\\?", keyString);
        String valueJson = carTemplate.replaceAll("\\?make", make);
        valueJson = valueJson.replaceAll("\\?model", model);
        valueJson = valueJson.replaceAll("\\?list", list);
        valueJson = valueJson.replaceAll("\\?set", set);
        valueJson = valueJson.replaceAll("\\?map", map);
        getLogWriter().info("Putting key with json key : " + keyJson);
        getLogWriter().info("Putting key with json valye : " + valueJson);
        command = command + " " + "--key=" + keyJson + " --value=" + valueJson + " --region=" + DATA_REGION_NAME_PATH;
        command = command + " --key-class=" + Key1.class.getCanonicalName() + " --value-class=" + Car.class.getCanonicalName();
        CommandResult cmdResult = executeCommand(command);
        printCommandOutput(cmdResult);
        assertEquals(Result.Status.OK, cmdResult.getStatus());
        validateResult(cmdResult, true);
    }
    SerializableRunnable checkPutKeys = 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 + 5; i++) {
                String keyString = keyPrefix + i;
                Key1 key = new Key1();
                key.setId(keyString);
                key.setName("name" + keyString);
                assertEquals(true, region.containsKey(key));
                // Bug #51175
                if (i >= COUNT) {
                    Car car = (Car) region.get(key);
                    assertNotNull(car.getAttributes());
                    assertNotNull(car.getAttributeSet());
                    assertNotNull(car.getColors());
                }
            }
        }
    };
    vm1.invoke(checkPutKeys);
    vm2.invoke(checkPutKeys);
    doBugCheck50449();
}
Also used : 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) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Region(org.apache.geode.cache.Region) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) Cache(org.apache.geode.cache.Cache) InternalCache(org.apache.geode.internal.cache.InternalCache) 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)

Example 2 with Key1

use of org.apache.geode.management.internal.cli.dto.Key1 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 3 with Key1

use of org.apache.geode.management.internal.cli.dto.Key1 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)3 Region (org.apache.geode.cache.Region)3 InternalCache (org.apache.geode.internal.cache.InternalCache)3 Key1 (org.apache.geode.management.internal.cli.dto.Key1)3 CommandResult (org.apache.geode.management.internal.cli.result.CommandResult)3 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)3 VM (org.apache.geode.test.dunit.VM)3 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)3 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)3 Test (org.junit.Test)3 Car (org.apache.geode.management.internal.cli.dto.Car)2 Value2 (org.apache.geode.management.internal.cli.dto.Value2)2 Category (org.junit.experimental.categories.Category)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1