Package com.pardot.rhombus

Examples of com.pardot.rhombus.ConnectionManager


  @Test
  public void testInsertAsyncMulti() throws Exception {
    logger.debug("Starting testInsertAsync");

    //Build the connection manager
    ConnectionManager cm = getConnectionManager();

    //Build our keyspace definition object
    CKeyspaceDefinition definition = JsonUtil.objectFromJsonResource(CKeyspaceDefinition.class, this.getClass().getClassLoader(), "AuditKeyspace.js");
    assertNotNull(definition);

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

    final int numThreads = 10;
    final ExecutorService executorService = Executors.newFixedThreadPool(numThreads);
    List<Map<String, Object>> values = JsonUtil.rhombusMapFromResource(this.getClass().getClassLoader(), "DateRangeQueryTestData.js");
    final CDefinition objectAuditDef = definition.getDefinitions().get("object_audit");

    //Run through the inserts a few times and get a total time to execute
    long startTime = System.currentTimeMillis();
    for(int i = 0 ; i < 100 ; i++) {
      insertObjectSetAsync(numThreads, executorService, om, values, objectAuditDef);
    }
    logger.warn("Total time: {}ms", System.currentTimeMillis() - startTime);

    cm.teardown();
  }
View Full Code Here


  @Test
  public void testObjectMapper() throws Exception {
    logger.debug("Starting testObjectMapper");

    //Build the connection manager
    ConnectionManager cm = getConnectionManager();

    //Build our keyspace definition object
    CKeyspaceDefinition definition = JsonUtil.objectFromJsonResource(CKeyspaceDefinition.class, this.getClass().getClassLoader(), "CKeyspaceTestData.js");
    assertNotNull(definition);

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

    //Get a test object to insert
    Map<String, Object> testObject = JsonUtil.rhombusMapFromJsonMap(TestHelpers.getTestObject(0), definition.getDefinitions().get("testtype"));
    UUID key = (UUID) om.insert("testtype", testObject);

    //Query to get back the object from the database
    Map<String, Object> dbObject = om.getByKey("testtype", key);
    for (String dbKey : dbObject.keySet()) {
      //Verify that everything but the key is the same
      if (!dbKey.equals("id")) {
        assertEquals(testObject.get(dbKey), dbObject.get(dbKey));
      }
    }

    //Add another object with the same foreign key
    UUID key2 = (UUID) om.insert("testtype", JsonUtil.rhombusMapFromJsonMap(TestHelpers.getTestObject(1), definition.getDefinitions().get("testtype")));

    //Query by foreign key
    Criteria criteria = TestHelpers.getTestCriteria(0);
    long foreignKey = ((Integer) criteria.getIndexKeys().get("foreignid")).longValue();
    criteria.getIndexKeys().put("foreignid", foreignKey);
    List<Map<String, Object>> dbObjects = om.list("testtype", criteria);
    assertEquals(2, dbObjects.size());
    for (Map<String, Object> result : dbObjects) {
      assertEquals(foreignKey, result.get("foreignid"));
    }

    //Remove one of the objects we added
    om.delete("testtype", key);

    //Re-query by foreign key
    dbObjects = om.list("testtype", criteria);
    assertEquals(1, dbObjects.size());

    //Update the values of one of the objects
    Map<String, Object> testObject2 = JsonUtil.rhombusMapFromJsonMap(
        TestHelpers.getTestObject(2),
        definition.getDefinitions().get("testtype"));
    UUID key3 = om.update("testtype", key2, testObject2);

    //Get the updated object back and make sure it matches
    Map<String, Object> dbObject2 = om.getByKey("testtype", key3);
    testObject2.put("id", key2);
    for (String dbKey : dbObject2.keySet()) {
      //Verify that everything is the same
      assertEquals(testObject2.get(dbKey), dbObject2.get(dbKey));
    }

    //Get from the original index
    dbObjects = om.list("testtype", criteria);
    assertEquals(0, dbObjects.size());

    //Get from the new index
    Criteria criteria2 = TestHelpers.getTestCriteria(1);
    criteria2.getIndexKeys().put("foreignid", ((Integer) criteria2.getIndexKeys().get("foreignid")).longValue());
    dbObjects = om.list("testtype", criteria2);
    assertEquals(1, dbObjects.size());

    //an imediate request should return null, because we didnt wait for consistency
    assertEquals(null, om.getNextUpdateIndexRow(null));

    //Do another update
    Map<String, Object> testObject3 = Maps.newHashMap();
    testObject3.put("type", Integer.valueOf(7));
    UUID key4 = om.update("testtype", key2, testObject3);

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

    //Test that we can retrieve the proper update rows
    IndexUpdateRow row = om.getNextUpdateIndexRow(null);
    assertEquals("testtype", row.getObjectName());
    assertEquals(2, row.getIndexValues().size());
    //most recent should be at the front of the list
    assertEquals(7, row.getIndexValues().get(0).get("type"));
    assertEquals(5, row.getIndexValues().get(1).get("type"));
    assertEquals(778L, row.getIndexValues().get(0).get("foreignid"));
    assertEquals(778L, row.getIndexValues().get(1).get("foreignid"));
    assertEquals(333333L, row.getIndexValues().get(0).get("instance"));
    assertEquals(333333L, row.getIndexValues().get(1).get("instance"));

    //verify that if we try to get the next row it returns null
    assertEquals(null, om.getNextUpdateIndexRow(row.getRowKey()));

    //Teardown connections
    cm.teardown();
  }
View Full Code Here

        if(cassConfig == null){
            System.out.println("Could not parse cassandra configuration file "+cassConfigFileName);
            return false;
        }

        connectionManager = new ConnectionManager(cassConfig);
        connectionManager.setLogCql(cl.hasOption("c"));
        connectionManager.buildCluster();

        if(connectionManager == null){
            System.out.println("Could create cassandra connection manager from file "+cassConfigFileName);
View Full Code Here

    if(!cl.hasOption("keyspace")){
      displayHelpMessage();
      return false;
    }
    this.keyspaceName = cl.getOptionValue("keyspace");
    ConnectionManager cm = getConnectionManager();
    this.objectMapper = cm.getObjectMapper(this.keyspaceName);
    return true;
  }
View Full Code Here

TOP

Related Classes of com.pardot.rhombus.ConnectionManager

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.