Search in sources :

Example 1 with Car

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

use of org.apache.geode.management.internal.cli.dto.Car 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)

Example 3 with Car

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

the class DataCommandJsonJUnitTest method testCollectionTypesInJson.

@Test
public void testCollectionTypesInJson() {
    String json = "{'attributes':{'power':'90hp'},'make':'502.1825','model':'502.1825','colors':['red','white','blue'],'attributeSet':['red','white','blue'], 'attributeArray':['red','white','blue']}";
    Car car = (Car) JsonUtil.jsonToObject(json, Car.class);
    assertNotNull(car.getAttributeSet());
    assertTrue(car.getAttributeSet() instanceof HashSet);
    assertEquals(3, car.getAttributeSet().size());
    assertNotNull(car.getColors());
    assertTrue(car.getColors() instanceof ArrayList);
    assertEquals(3, car.getColors().size());
    assertNotNull(car.getAttributes());
    assertTrue(car.getAttributes() instanceof HashMap);
    assertEquals(1, car.getAttributes().size());
    assertTrue(car.getAttributes().containsKey("power"));
    assertNotNull(car.getAttributeArray());
    assertTrue(car.getAttributeArray() instanceof String[]);
    assertEquals(3, car.getAttributeArray().length);
}
Also used : Car(org.apache.geode.management.internal.cli.dto.Car) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Aggregations

Car (org.apache.geode.management.internal.cli.dto.Car)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 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 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 Category (org.junit.experimental.categories.Category)2 Value2 (org.apache.geode.management.internal.cli.dto.Value2)1 UnitTest (org.apache.geode.test.junit.categories.UnitTest)1