Package com.pardot.rhombus

Examples of com.pardot.rhombus.ObjectMapper


        //Rebuild the keyspace and get the object mapper
        cm.buildKeyspace(keyspaceDefinition, true);
        logger.debug("Built keyspace: {}", keyspaceDefinition.getName());
        cm.setDefaultKeyspace(keyspaceDefinition);
        ObjectMapper om = cm.getObjectMapper();
        om.setLogCql(true);
        om.truncateTables();

        // This is the only static table definition this test keyspace has
        List<String> staticTableNames = Arrays.asList(testUniqueTableName);

        //Insert our test data into the SSTable
        // For this test, all this data goes into the one table we have defined
        List<Map<String, Object>> values = JsonUtil.rhombusMapFromResource(this.getClass().getClassLoader(), "SSTableWriterSimpleTestData.js");
        // Tack on time based UUIDs because we don't really care what the UUID values are
        for (Map<String, Object> map : values) {
            map.put("id", UUIDs.startOf(Long.parseLong(map.get("created_at").toString(), 10)));
        }
        // Build the map to insert that we'll actually pass in
        Map<String, List<Map<String, Object>>> insert = new HashMap<String, List<Map<String, Object>>>();
        for (String staticTableName : staticTableNames) {
            insert.put(staticTableName, values);
        }

        // Actually insert the data into the SSTableWriters
        om.initializeSSTableWriters(false);
        om.insertIntoSSTable(insert);
        om.completeSSTableWrites();

        // Figure out all the table names (including index tables) so we can load them into Cassandra
        File[] tableDirs = keyspaceDir.listFiles();
        assertNotNull(tableDirs);
        List<String> allTableNames = Lists.newArrayList();
        for (File file : tableDirs) {
            if (file != null) {
                allTableNames.add(file.getName());
            }
        }
        for (String tableName : allTableNames) {
            String SSTablePath = keyspaceName + "/" + tableName;

            // Load the SSTables into Cassandra
            ProcessBuilder builder = new ProcessBuilder("sstableloader", "-d", "localhost", SSTablePath);
            builder.redirectErrorStream(true);
            Process p = builder.start();
            BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
            long startTime = System.currentTimeMillis();
            // TODO: sleep is the devil
            while (!r.readLine().contains("100%") && ((System.currentTimeMillis() - startTime) < 10000)) {
                Thread.sleep(100);
            }
        }

        String staticTableName = staticTableNames.get(0);
        for (Map<String, Object> expected : values) {
            Map<String, Object> actual = om.getByKey(staticTableName, expected.get("id"));
            assertEquals(expected, actual);
        }

        Map<String, Map<String, Object>> indexedExpected = Maps.uniqueIndex(values, new Function<Map<String, Object>,String>() {
            public String apply(Map<String, Object> input) {
                return input.get("id").toString();
            }});
        // Confirm get by index_1 query
        SortedMap<String, Object> indexValues = Maps.newTreeMap();
        indexValues.put("index_1", "index1");
        Criteria criteria = new Criteria();
        criteria.setIndexKeys(indexValues);
        criteria.setLimit(50L);
        List<Map<String, Object>> results = om.list(testUniqueTableName, criteria);
        Map<String, Map<String, Object>> indexedResults;
        indexedResults = Maps.uniqueIndex(results, new Function<Map<String, Object>, String>() {
            public String apply(Map<String, Object> input) {
                return input.get("id").toString();
            }
        });
        Map<String, Map<String, Object>> indexedExpected1 = Maps.newHashMap(indexedExpected);
        // Index_1 test data doesn't include value 4
        indexedExpected1.remove("864f1400-2a7e-11b2-8080-808080808080");
        assertEquals(indexedExpected1, indexedResults);

        // Confirm get by index_2 query
        indexValues = Maps.newTreeMap();
        indexValues.put("index_2", "index2");
        criteria = new Criteria();
        criteria.setIndexKeys(indexValues);
        criteria.setLimit(50L);
        results = om.list(testUniqueTableName, criteria);

        indexedResults = Maps.uniqueIndex(results, new Function<Map<String, Object>,String>() {
            public String apply(Map<String, Object> input) {
                return input.get("id").toString();
            }});
View Full Code Here


        //Rebuild the keyspace and get the object mapper
        cm.buildKeyspace(keyspaceDefinition, true);
        logger.debug("Built keyspace: {}", keyspaceDefinition.getName());
        cm.setDefaultKeyspace(keyspaceDefinition);
        ObjectMapper om = cm.getObjectMapper();
        om.setLogCql(true);
        om.truncateTables();

        // This is the only static table definition this test keyspace has
        List<String> staticTableNames = Arrays.asList(testUniqueTableName);

        //Insert our test data into the SSTable
        // For this test, all this data goes into the one table we have defined
        List<Map<String, Object>> values = JsonUtil.rhombusMapFromResource(this.getClass().getClassLoader(), "SSTableWriterSimpleTestData.js");
        // Tack on time based UUIDs because we don't really care what the UUID values are
        for (Map<String, Object> map : values) {
            map.put("id", UUIDs.startOf(Long.parseLong(map.get("created_at").toString(), 10)));
            // For this test, remove the actual values so we see what happens if we try to insert nulls
            map.remove("value");
        }
        // Build the map to insert that we'll actually pass in
        Map<String, List<Map<String, Object>>> insert = new HashMap<String, List<Map<String, Object>>>();
        for (String staticTableName : staticTableNames) {
            insert.put(staticTableName, values);
        }

        // Actually insert the data into the SSTableWriters
        om.initializeSSTableWriters(false);
        om.insertIntoSSTable(insert);
        om.completeSSTableWrites();

        // Figure out all the table names (including index tables) so we can load them into Cassandra
        File[] tableDirs = keyspaceDir.listFiles();
        assertNotNull(tableDirs);
        List<String> allTableNames = Lists.newArrayList();
        for (File file : tableDirs) {
            if (file != null) {
                allTableNames.add(file.getName());
            }
        }
        for (String tableName : allTableNames) {
            String SSTablePath = keyspaceName + "/" + tableName;

            // Load the SSTables into Cassandra
            ProcessBuilder builder = new ProcessBuilder("sstableloader", "-d", "localhost", SSTablePath);
            builder.redirectErrorStream(true);
            Process p = builder.start();
            BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
            long startTime = System.currentTimeMillis();
            // TODO: sleep is the devil
            while (!r.readLine().contains("100%") && ((System.currentTimeMillis() - startTime) < 10000)) {
                Thread.sleep(100);
            }
        }

        String staticTableName = staticTableNames.get(0);
        for (Map<String, Object> expected : values) {
            // Expect to get the null "value" back
            expected.put("value", null);
            Map<String, Object> actual = om.getByKey(staticTableName, expected.get("id"));
            assertEquals(expected, actual);
        }

        Map<String, Map<String, Object>> indexedExpected = Maps.uniqueIndex(values, new Function<Map<String, Object>,String>() {
            public String apply(Map<String, Object> input) {
                return input.get("id").toString();
            }});
        // Confirm get by index_1 query
        SortedMap<String, Object> indexValues = Maps.newTreeMap();
        indexValues.put("index_1", "index1");
        Criteria criteria = new Criteria();
        criteria.setIndexKeys(indexValues);
        criteria.setLimit(50L);
        List<Map<String, Object>> results = om.list(testUniqueTableName, criteria);
        Map<String, Map<String, Object>> indexedResults;
        indexedResults = Maps.uniqueIndex(results, new Function<Map<String, Object>, String>() {
            public String apply(Map<String, Object> input) {
                return input.get("id").toString();
            }
        });
        Map<String, Map<String, Object>> indexedExpected1 = Maps.newHashMap(indexedExpected);
        // Index_1 test data doesn't include value 4
        indexedExpected1.remove("864f1400-2a7e-11b2-8080-808080808080");
        assertEquals(indexedExpected1, indexedResults);

        // Confirm get by index_2 query
        indexValues = Maps.newTreeMap();
        indexValues.put("index_2", "index2");
        criteria = new Criteria();
        criteria.setIndexKeys(indexValues);
        criteria.setLimit(50L);
        results = om.list(testUniqueTableName, criteria);

        indexedResults = Maps.uniqueIndex(results, new Function<Map<String, Object>,String>() {
            public String apply(Map<String, Object> input) {
                return input.get("id").toString();
            }});
View Full Code Here

        //Rebuild the keyspace and get the object mapper
        cm.buildKeyspace(keyspaceDefinition, true);
        logger.debug("Built keyspace: {}", keyspaceDefinition.getName());
        cm.setDefaultKeyspace(keyspaceDefinition);
        ObjectMapper om = cm.getObjectMapper();
        om.setLogCql(true);
        om.truncateTables();

        // This is the only static table definition this test keyspace has
        List<String> staticTableNames = Arrays.asList(testUniqueTableName);

        //Insert our test data into the SSTable
        // For this test, all this data goes into the one table we have defined
        List<Map<String, Object>> values = JsonUtil.rhombusMapFromResource(this.getClass().getClassLoader(), "SSTableWriterSimpleTestData.js");
        // Tack on time based UUIDs because we don't really care what the UUID values are
        for (Map<String, Object> map : values) {
            map.put("id", UUIDs.startOf(Long.parseLong(map.get("created_at").toString(), 10)));
            // For this test, remove the index values so we see what happens if we try to insert nulls for index values
            map.remove("index_1");
        }
        // Build the map to insert that we'll actually pass in
        Map<String, List<Map<String, Object>>> insert = new HashMap<String, List<Map<String, Object>>>();
        for (String staticTableName : staticTableNames) {
            insert.put(staticTableName, values);
        }

        // Actually insert the data into the SSTableWriters
        om.initializeSSTableWriters(false);
        om.insertIntoSSTable(insert);
        om.completeSSTableWrites();

        // Figure out all the table names (including index tables) so we can load them into Cassandra
        File[] tableDirs = keyspaceDir.listFiles();
        assertNotNull(tableDirs);
        List<String> allTableNames = Lists.newArrayList();
        for (File file : tableDirs) {
            if (file != null) {
                allTableNames.add(file.getName());
            }
        }
        for (String tableName : allTableNames) {
            String SSTablePath = keyspaceName + "/" + tableName;

            // Load the SSTables into Cassandra
            ProcessBuilder builder = new ProcessBuilder("sstableloader", "-d", "localhost", SSTablePath);
            builder.redirectErrorStream(true);
            Process p = builder.start();
            BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
            long startTime = System.currentTimeMillis();
            // TODO: sleep is the devil
            while (!r.readLine().contains("100%") && ((System.currentTimeMillis() - startTime) < 10000)) {
                Thread.sleep(100);
            }
        }

        String staticTableName = staticTableNames.get(0);
        // Confirm get by id query
        for (Map<String, Object> expected : values) {
            // Expect to get the null "value" back
            expected.put("index_1", null);
            Map<String, Object> actual = om.getByKey(staticTableName, expected.get("id"));
            assertEquals(expected, actual);
        }

        // Index expected data by the value, which we will use as a faux index for testing
        Map<String, Map<String, Object>> indexedExpected = Maps.uniqueIndex(values, new Function<Map<String, Object>,String>() {
            public String apply(Map<String, Object> input) {
                return input.get("value").toString();
            }});
        // Confirm get by index_1 query
        SortedMap<String, Object> indexValues = Maps.newTreeMap();
        indexValues.put("index_1", "index1");
        Criteria criteria = new Criteria();
        criteria.setIndexKeys(indexValues);
        criteria.setLimit(50L);
        List<Map<String, Object>> results = om.list(testUniqueTableName, criteria);
        assertEquals("Index 1 values were null for this test, query on index 1 should return 0 results", 0, results.size());

        // Confirm get by index_2 query
        indexValues = Maps.newTreeMap();
        indexValues.put("index_2", "index2");
        criteria = new Criteria();
        criteria.setIndexKeys(indexValues);
        criteria.setLimit(50L);
        results = om.list(testUniqueTableName, criteria);

        // Index results by the value, which we will use as a faux index for testing
        Map<String, Map<String, Object>> indexedResults = Maps.uniqueIndex(results, new Function<Map<String, Object>,String>() {
            public String apply(Map<String, Object> input) {
                return input.get("value").toString();
View Full Code Here

        //Rebuild the keyspace and get the object mapper
        cm.buildKeyspace(keyspaceDefinition, true);
        logger.debug("Built keyspace: {}", keyspaceDefinition.getName());
        cm.setDefaultKeyspace(keyspaceDefinition);
        ObjectMapper om = cm.getObjectMapper();
        om.setLogCql(true);
        om.truncateTables();

        // This is the only static table definition this test keyspace has
        List<String> staticTableNames = Arrays.asList(testUniqueTableName);

        //Insert our test data into the SSTable
        // For this test, all this data goes into the one table we have defined
        List<Map<String, Object>> values = JsonUtil.rhombusMapFromResource(this.getClass().getClassLoader(), "SSTableWriterNonUuidPkTestData.js");
        // Build the map to insert that we'll actually pass in
        Map<String, List<Map<String, Object>>> insert = new HashMap<String, List<Map<String, Object>>>();
        for (String staticTableName : staticTableNames) {
            insert.put(staticTableName, values);
        }

        // Actually insert the data into the SSTableWriters
        om.initializeSSTableWriters(false);
        om.insertIntoSSTable(insert);
        om.completeSSTableWrites();

        // Figure out all the table names (including index tables) so we can load them into Cassandra
        File[] tableDirs = keyspaceDir.listFiles();
        assertNotNull(tableDirs);
        List<String> allTableNames = Lists.newArrayList();
        for (File file : tableDirs) {
            if (file != null) {
                allTableNames.add(file.getName());
            }
        }
        for (String tableName : allTableNames) {
            String SSTablePath = keyspaceName + "/" + tableName;

            // Load the SSTables into Cassandra
            ProcessBuilder builder = new ProcessBuilder("sstableloader", "-d", "localhost", SSTablePath);
            builder.redirectErrorStream(true);
            Process p = builder.start();
            BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
            long startTime = System.currentTimeMillis();
            // TODO: sleep is the devil
            while (!r.readLine().contains("100%") && ((System.currentTimeMillis() - startTime) < 10000)) {
                Thread.sleep(100);
            }
        }

        String staticTableName = staticTableNames.get(0);
        for (Map<String, Object> expected : values) {
            Map<String, Object> actual = om.getByKey(staticTableName, expected.get("id"));
            assertEquals(expected, actual);
        }

        // Clean up the SSTable directories after ourselves
        FileUtils.deleteRecursive(new File(keyspaceName));
View Full Code Here

    assertNotNull(definition);

    //Rebuild the keyspace and get the object mapper
    cm.buildKeyspace(definition, true);
    cm.setDefaultKeyspace(definition);
    ObjectMapper om = cm.getObjectMapper();
    om.truncateTables();

    CDefinition def1 = om.getKeyspaceDefinition_ONLY_FOR_TESTING().getDefinitions().get("testtype");
    //do an insert on an object
    Map<String, Object> testObject = Maps.newTreeMap();
    testObject.put("foreignid", Long.valueOf(100));
    testObject.put("type", Integer.valueOf(101));
    testObject.put("instance", Long.valueOf(102));
    testObject.put("filtered", Integer.valueOf(103));
    testObject.put("data1", "This is data 1");
    testObject.put("data2", "This is data 2");
    testObject.put("data3", "This is data 3");

    UUID key = (UUID)om.insert("testtype", testObject);

    testObject.put("foreignid", Long.valueOf(200));
    testObject.put("type", Integer.valueOf(201));
    testObject.put("instance", Long.valueOf(202));
    testObject.put("filtered", Integer.valueOf(203));

    //manually insert that object incorrectly into other indexes
    List<CQLStatement> insertStatements = Lists.newArrayList();
    for(CIndex i : def1.getIndexes().values()){
      om.getCqlGenerator_ONLY_FOR_TESTING().addCQLStatmentsForIndexInsert(
          keyspace,
          true,
          insertStatements,
          def1,
          testObject,
          i,
          key,
          om.getCqlGenerator_ONLY_FOR_TESTING().makeFieldAndValueList(def1, testObject), null, null);
    }
    for(CQLStatement s: insertStatements){
      om.getCqlExecutor().executeSync(s);
    }

    //manually record those incorrect values in the update table
    CQLStatement cql = om.getCqlGenerator_ONLY_FOR_TESTING().makeInsertUpdateIndexStatement(
        keyspace,
        def1,
        key, def1.makeIndexValues(testObject));
    om.getCqlExecutor().executeSync(cql);

    //now manually record an update back to the original in the update table to simulate an eventual consistency issue
    Map<String, Object> testObjectOriginal = Maps.newTreeMap();
    testObjectOriginal.put("foreignid", Long.valueOf(100));
    testObjectOriginal.put("type", Integer.valueOf(101));
    testObjectOriginal.put("instance", Long.valueOf(102));
    testObjectOriginal.put("filtered", Integer.valueOf(103));
    testObjectOriginal.put("data1", "This is data 1");
    testObjectOriginal.put("data2", "This is data 2");
    testObjectOriginal.put("data3", "This is data 3");
    cql = om.getCqlGenerator_ONLY_FOR_TESTING().makeInsertUpdateIndexStatement(
        definition.getName(),
        def1,
        key, def1.makeIndexValues(testObjectOriginal));
    om.getCqlExecutor().executeSync(cql);

    //verify that the object returns different values in the static table and on those (or some of those) indexes
    Map<String, Object> staticTableObject = om.getByKey("testtype", key);
    assertEquals(100L,staticTableObject.get("foreignid"));
    assertEquals(101,staticTableObject.get("type"));
    assertEquals(103,staticTableObject.get("filtered"));
    assertEquals("This is data 1",staticTableObject.get("data1"));

    Criteria criteria = new Criteria();
    SortedMap<String,Object> values = Maps.newTreeMap();
    values.put("foreignid", Long.valueOf(200L));
    criteria.setIndexKeys(values);
    criteria.setLimit(0L);
    List<Map<String, Object>> indexObjects = om.list("testtype", criteria);
    assertEquals(1, indexObjects.size());
    assertEquals(staticTableObject.get("data1"),indexObjects.get(0).get("data1"));
    assertEquals(200L,indexObjects.get(0).get("foreignid"));
    assertEquals(201,indexObjects.get(0).get("type"));
    assertEquals(203,indexObjects.get(0).get("filtered"));


    //wait for consistency
    Thread.sleep(3000);

    //now run the processor
    UpdateProcessor up = new UpdateProcessor(om);
    up.process(9999L);

    //verify that the object is no longer present in the invalid indexes

    //Should be missing from the bad index
    criteria = new Criteria();
    values = Maps.newTreeMap();
    values.put("foreignid", Long.valueOf(200));
    criteria.setIndexKeys(values);
    criteria.setLimit(0L);
    indexObjects = om.list("testtype", criteria);
    assertEquals(0, indexObjects.size());

    //But is should be present in the correct index
    criteria = new Criteria();
    values = Maps.newTreeMap();
    values.put("foreignid", Long.valueOf(100));
    criteria.setIndexKeys(values);
    indexObjects = om.list("testtype", criteria);
    assertEquals(1, indexObjects.size());
    assertEquals(staticTableObject.get("data1"),indexObjects.get(0).get("data1"));
    assertEquals(100L,indexObjects.get(0).get("foreignid"));
    assertEquals(101,indexObjects.get(0).get("type"));
    assertEquals(103,indexObjects.get(0).get("filtered"));
View Full Code Here

    assertNotNull(definition);

    //Rebuild the keyspace and get the object mapper
    cm.buildKeyspace(definition, true);
    cm.setDefaultKeyspace(definition);
    ObjectMapper om = cm.getObjectMapper();
    om.truncateTables();

    //do an insert on an object
    Map<String, Object> testObject = Maps.newTreeMap();
    testObject.put("foreignid", Long.valueOf(100));
    testObject.put("type", Integer.valueOf(101));
    testObject.put("instance", Long.valueOf(102));
    testObject.put("filtered", Integer.valueOf(103));
    testObject.put("data1", "This is data 1");
    testObject.put("data2", "This is data 2");
    testObject.put("data3", "This is data 3");

    UUID key = (UUID)om.insert("testtype", testObject);

    Map<String, Object> updateObj = Maps.newTreeMap();
    updateObj.put("foreignid", Long.valueOf(1));
    om.update("testtype",key, updateObj);

    updateObj = Maps.newTreeMap();
    updateObj.put("foreignid", Long.valueOf(2));
    om.update("testtype",key, updateObj);

    updateObj = Maps.newTreeMap();
    updateObj.put("foreignid", Long.valueOf(3));
    om.update("testtype",key, updateObj);

    updateObj = Maps.newTreeMap();
    updateObj.put("foreignid", Long.valueOf(4));
    om.update("testtype",key, updateObj);

    updateObj = Maps.newTreeMap();
    updateObj.put("foreignid", Long.valueOf(5));
    om.update("testtype",key, updateObj);

    Thread.sleep(2000);

    updateObj = Maps.newTreeMap();
    updateObj.put("foreignid", Long.valueOf(6));
    om.update("testtype",key, updateObj);

    Thread.sleep(2000);


View Full Code Here

    assertNotNull(definition);

    //Rebuild the keyspace and get the object mapper
    cm.buildKeyspace(definition, false);
    cm.setDefaultKeyspace(definition);
    ObjectMapper om = cm.getObjectMapper();
    om.truncateTables();

    //do an insert on an object
    Map<String, Object> testObject = Maps.newTreeMap();
    testObject.put("foreignid", Long.valueOf(100));
    testObject.put("type", Integer.valueOf(101));
    testObject.put("instance", Long.valueOf(102));
    testObject.put("filtered", Integer.valueOf(103));
    testObject.put("data1", "This is data 1");
    testObject.put("data2", "This is data 2");
    testObject.put("data3", "This is data 3");

    Map<String, Object> testObject2 = Maps.newTreeMap();
    testObject2.put("foreignid", Long.valueOf(200));
    testObject2.put("type", Integer.valueOf(201));
    testObject2.put("instance", Long.valueOf(202));
    testObject2.put("filtered", Integer.valueOf(203));
    testObject2.put("data1", "This is data 2-1");
    testObject2.put("data2", "This is data 2-2");
    testObject2.put("data3", "This is data 2-3");

    UUID key = (UUID)om.insert("testtype", testObject);
    Map<String, Object> updateObj = Maps.newTreeMap();
    updateObj.put("foreignid", 1l);
    om.update("testtype", key, updateObj);

    updateObj = Maps.newTreeMap();
    updateObj.put("foreignid", 2l);
    om.update("testtype", key, updateObj);

    UUID key2 = (UUID)om.insert("testtype", testObject2);
    updateObj = Maps.newTreeMap();
    updateObj.put("foreignid", 4l);
    om.update("testtype", key2, updateObj);

    updateObj = Maps.newTreeMap();
    updateObj.put("foreignid", 5l);
    om.update("testtype", key2, updateObj);

    Thread.sleep(3000);

    // Test row examine limit
    UpdateProcessor up = new UpdateProcessor(om);
View Full Code Here

    assertNotNull(definition);

    //Rebuild the keyspace and get the object mapper
    cm.buildKeyspace(definition, true);
    cm.setDefaultKeyspace(definition);
    ObjectMapper om = cm.getObjectMapper();
    om.truncateTables();

    //do an insert on an object
    Map<String, Object> testObject = Maps.newTreeMap();
    testObject.put("foreignid", null); //null index value
    testObject.put("type", Integer.valueOf(101));
    testObject.put("instance", Long.valueOf(102));
    testObject.put("filtered", Integer.valueOf(103));
    testObject.put("data1", "This is data 1");
    testObject.put("data2", "This is data 2");
    testObject.put("data3", "This is data 3");

    UUID key = (UUID)om.insert("testtype", testObject);

    //now update with a value for foreignid and make another index value (instance) be null
    testObject = Maps.newTreeMap();
    testObject.put("foreignid", 77L);
    testObject.put("instance", null);
    om.update("testtype",key,testObject);

    //now reverse it
    testObject = Maps.newTreeMap();
    testObject.put("foreignid", null);
    testObject.put("instance", 77L);
    om.update("testtype",key,testObject);

    //now back again (the update processor needs to see multiple updates to hit a process case.
    testObject = Maps.newTreeMap();
    testObject.put("foreignid", 77L);
    testObject.put("instance", null);
    om.update("testtype",key,testObject);

    //now back again (the update processor needs to see multiple updates to hit a process case.
    testObject = Maps.newTreeMap();
    testObject.put("foreignid", 77L);
    testObject.put("instance", null);
    om.update("testtype",key,testObject);

    Thread.sleep(3500);

    //now run the processor
    UpdateProcessor up = new UpdateProcessor(om);
    up.process(9999L);

    //But is should be present in the correct index
    Criteria criteria = new Criteria();
    SortedMap<String,Object> values = Maps.newTreeMap();
    values.put("foreignid", Long.valueOf(77));
    criteria.setIndexKeys(values);
    List<Map<String,Object>> indexObjects = om.list("testtype", criteria);
    assertEquals(1, indexObjects.size());
    assertEquals(null,indexObjects.get(0).get("instance"));
    assertEquals(77L,indexObjects.get(0).get("foreignid"));
    assertEquals(101,indexObjects.get(0).get("type"));
    assertEquals(103,indexObjects.get(0).get("filtered"));
View Full Code Here

    //Rebuild the keyspace and get the object mapper
    cm.buildKeyspace(definition, true);
    logger.debug("Built keyspace: {}", definition.getName());
    cm.setDefaultKeyspace(definition);
    ObjectMapper om = cm.getObjectMapper();
    om.setLogCql(true);

    // Insert 20 values
    List<Map<String, Object>> values = this.getNValues(20, index1Value, index2Value);
    for(Map<String, Object> insertValue : values) {
      om.insert(objectType, insertValue);
    }

    // Get back the first 10
    List<Map<String, Object>> first10 = om.scanTableWithStartToken(objectType, Long.MIN_VALUE, Long.MAX_VALUE, 10l);
    assertEquals(10, first10.size());

    // Get back the rest, starting with the last id in the first set
    List<Map<String, Object>> next10 = om.scanTableWithStartId(objectType, String.valueOf(first10.get(first10.size()-1).get("id")), Long.MAX_VALUE, 100l);
    assertEquals(10, next10.size());
    for(Map<String, Object> value : next10) {
      assertFalse(valuesContainsId(first10, value.get("id")));
    }
View Full Code Here

    assertNotNull(definition);

    //Rebuild the keyspace and get the object mapper
    cm.buildKeyspace(definition, true);
    cm.setDefaultKeyspace(definition);
    ObjectMapper om = cm.getObjectMapper();
    CDefinition def1 = om.getKeyspaceDefinition_ONLY_FOR_TESTING().getDefinitions().get("testtype");


    //do an insert on an object
    //make some objects to insert
    List<Map<String,Object>> toInserts = Lists.newArrayList();
    int numberOfObjects = 400;
    //int numberOfObjects = 100;
    for(int i = 0; i < numberOfObjects; i++){
      Map<String, Object> testObject = Maps.newTreeMap();
      testObject.put("foreignid", Long.valueOf(33339999));
      testObject.put("type", Integer.valueOf(i%5));
      testObject.put("instance", Long.valueOf(i%10));
      testObject.put("filtered", Integer.valueOf(1));
      testObject.put("data1", "This is data 1 "+i);
      testObject.put("data2", "This is data 2 "+i);
      testObject.put("data3", "This is data 3 "+i);
      toInserts.add(testObject);
    }

    Map<String,List<Map<String,Object>>> objects = Maps.newHashMap();
    objects.put("testtype", toInserts);

    long start = 0;
    long end = 0;
    long asyncTime = 0;
    long syncTime = 0;

    //insert sync
    om.setExecuteAsync(false);
    start = System.currentTimeMillis();
    om.insertBatchMixed(objects);
    end = System.currentTimeMillis();
    syncTime = end - start;

    //Rebuild the keyspace and get the object mapper
    cm = getConnectionManager();
    cm.buildKeyspace(definition, true);
    cm.setDefaultKeyspace(definition);
    om = cm.getObjectMapper();
    def1 = om.getKeyspaceDefinition_ONLY_FOR_TESTING().getDefinitions().get("testtype");


    //insert async
    om.setExecuteAsync(true);
    start = System.currentTimeMillis();
    om.insertBatchMixed(objects);
    end = System.currentTimeMillis();
    asyncTime = end - start;




    logger.info("Insert Speed Results");
    logger.info("======================");
    logger.info("Sync Time ms: " + syncTime);
    logger.info("Async Time ms: " + asyncTime);

    //testObject.put("foreignid", Long.valueOf(33339999));
    //Query it back out
    //Make sure that we have the proper number of results
    SortedMap<String, Object> indexValues = Maps.newTreeMap();
    indexValues.put("foreignid", Long.valueOf(33339999));
    Criteria criteria = new Criteria();
    criteria.setIndexKeys(indexValues);
    Thread.sleep(4000);
    int count = om.list("testtype",criteria).size();
    logger.info("======================");
    logger.info("Retrieved count of " + count);
    logger.info("======================");
    assertEquals(numberOfObjects,count);
View Full Code Here

TOP

Related Classes of com.pardot.rhombus.ObjectMapper

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.