Package com.pardot.rhombus

Examples of com.pardot.rhombus.ConnectionManager


        "-keyspacefile", workingpath + "cli-functional-keyspacedef.js",
        "-f"
    ).toArray()));

    //now verify that the keyspace was created and is working
    ConnectionManager cm = getConnectionManager();
    ObjectMapper om = cm.getObjectMapper("clifunctional");
    CKeyspaceDefinition keyspace = om.getKeyspaceDefinition_ONLY_FOR_TESTING();
    assertEquals("clifunctional", keyspace.getName());
    assertEquals(3, keyspace.getDefinitions().get("clitest").getFields().size());
    assertEquals(2, keyspace.getDefinitions().get("clitest").getIndexes().size());


    //now migrate the keyspace
    assertTrue(RhombusCli.runit((String[]) Arrays.asList(
        "RunMigration",
        "-cassconfig", workingpath + "cassandra-functional.js",
        "-newkeyspacefile", workingpath + "cli-functional-keyspacedef-migration.js",
        "-keyspace", "clifunctional"
    ).toArray()));

    //now verify that the keyspace was migrated and is working
    cm = getConnectionManager();
    om = cm.getObjectMapper("clifunctional");
    keyspace = om.getKeyspaceDefinition_ONLY_FOR_TESTING();
    assertEquals("clifunctional", keyspace.getName());
    assertEquals(3, keyspace.getDefinitions().get("clitest").getFields().size());
    assertEquals(3, keyspace.getDefinitions().get("clitest").getIndexes().size());
    assertEquals(2, keyspace.getDefinitions().get("clitest2").getIndexes().size());

    cm.teardown();
  }
View Full Code Here


        "-keyspacefile", workingpath+"cli-functional-keyspacedef.js",
        "-f"
    ).toArray()));

    //now verify that the keyspace was created and is working
    ConnectionManager cm = getConnectionManager();
    ObjectMapper om = cm.getObjectMapper("clifunctional");
    CKeyspaceDefinition keyspace = om.getKeyspaceDefinition_ONLY_FOR_TESTING();
    assertEquals("clifunctional", keyspace.getName());
    assertEquals(3, keyspace.getDefinitions().get("clitest").getFields().size());
    assertEquals(2, keyspace.getDefinitions().get("clitest").getIndexes().size());


    //now migrate the keyspace
    assertTrue(RhombusCli.runit((String[])Arrays.asList(
        "SetCompaction",
        "-cassconfig", workingpath+"cassandra-functional.js",
        "-keyspace", "clifunctional",
        "-strategy", "LeveledCompactionStrategy",
        "-sstableSize", "5",
        "-c"
    ).toArray()));

    //now verify that the keyspace was migrated and is working
    //cm = getConnectionManager();
    //ResultSet result = cm.getEmptySession().execute("describe keyspace clifunctional;");
    //result.one();

    cm.teardown();
  }
View Full Code Here

    String index2Value = "value2";

    logger.debug("Starting testNullIndexValues");

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

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

    //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);

    List<Map<String, Object>> values = this.getNValues(1, index1Value, index2Value);
    UUID id = (UUID)om.insert(objectType, values.get(0));

    //Get back the data and make sure things match
    Map<String, Object> result = om.getByKey(objectType, id);
    assertEquals(index1Value, result.get("index_1"));
    assertEquals(index2Value, result.get("index_2"));
    assertEquals("0", result.get("value"));

    //Update the object
    Map<String, Object> updates = Maps.newHashMap();
    updates.put("index_2", null);
    om.update(objectType, id, updates);

    //Get it back by id
    result = om.getByKey(objectType, id);
    assertEquals("0", result.get("value"));
    assertNull(result.get("index_2"));

    //Query back the data by first index
    Criteria criteria = new Criteria();
    SortedMap<String, Object> indexKeys = new TreeMap<String, Object>();
    indexKeys.put("index_1", "value1");
    criteria.setIndexKeys(indexKeys);
    criteria.setOrdering("DESC");
    criteria.setLimit(50l);
    List<Map<String, Object>> dbObjects = om.list(objectType, criteria);
    assertEquals(1, dbObjects.size());
    assertEquals(null, dbObjects.get(0).get("index_2"));

    //Query back the data by second index
    criteria = new Criteria();
    indexKeys = new TreeMap<String, Object>();
    indexKeys.put("index_2", "value2");
    criteria.setIndexKeys(indexKeys);
    criteria.setOrdering("DESC");
    criteria.setLimit(50l);
    dbObjects = om.list(objectType, criteria);
    assertEquals(0, dbObjects.size());

    cm.teardown();
  }
View Full Code Here

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

    //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);
    ObjectMapper om = cm.getObjectMapper();
    om.setLogCql(true);

    //Insert our test data
    List<Map<String, Object>> values = JsonUtil.rhombusMapFromResource(this.getClass().getClassLoader(), "NullIndexValuesTestData.js");
    Map<String, Object> object = values.get(0);
    Long createdAt = (Long)(object.get("created_at"));
    logger.debug("Inserting audit with created_at: {}", createdAt);
    UUID id = (UUID)om.insert("object_audit", JsonUtil.rhombusMapFromJsonMap(object,definition.getDefinitions().get("object_audit")), createdAt);

    //Get back the data and make sure things match
    Map<String, Object> result = om.getByKey("object_audit", id);

    //Update the object
    Map<String, Object> updates = Maps.newHashMap();
    updates.put("object_id", UUID.fromString("00000003-0000-0030-0040-000000040000"));
    om.update("object_audit", id, updates);


    //Query back the data
    Criteria criteria = new Criteria();
    SortedMap<String, Object> indexKeys = new TreeMap<String, Object>();
    indexKeys.put("account_id", UUID.fromString("00000003-0000-0030-0040-000000030000"));
    indexKeys.put("object_id", UUID.fromString("00000003-0000-0030-0040-000000040000"));
    indexKeys.put("object_type", "Account");
    criteria.setIndexKeys(indexKeys);
    criteria.setOrdering("DESC");
    criteria.setLimit(50l);

    List<Map<String, Object>> dbObjects = om.list("object_audit", criteria);
    assertEquals(1, dbObjects.size());

    cm.teardown();
  }
View Full Code Here

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

    //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);
    ObjectMapper om = cm.getObjectMapper();
    om.setLogCql(true);

    //Insert our test data
    List<Map<String, Object>> values = JsonUtil.rhombusMapFromResource(this.getClass().getClassLoader(), "NullIndexValuesTestData.js");
    Map<String, Object> object = values.get(0);
    Long createdAt = (Long)(object.get("created_at"));
    logger.debug("Inserting audit with created_at: {}", createdAt);
    UUID id = (UUID)om.insert("object_audit", JsonUtil.rhombusMapFromJsonMap(object,definition.getDefinitions().get("object_audit")), createdAt);

    //Update the object
    object.put("object_id", "00000003-0000-0030-0040-000000040000");
    om.update("object_audit", id, JsonUtil.rhombusMapFromJsonMap(object,definition.getDefinitions().get("object_audit")));

    //Get back the data and make sure things match
    Map<String, Object> result = om.getByKey("object_audit", id);
    assertNotNull(result);
    assertEquals(null, result.get("user_id"));

    cm.teardown();
  }
View Full Code Here

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

    //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);
    ObjectMapper om = cm.getObjectMapper();
    om.setLogCql(true);

    //Insert our test data
    List<Map<String, Object>> values = JsonUtil.rhombusMapFromResource(this.getClass().getClassLoader(), "NullIndexValuesTestData.js");
    Map<String, Object> object = values.get(0);
    Long createdAt = (Long)(object.get("created_at"));
    logger.debug("Inserting audit with created_at: {}", createdAt);
    UUID id = (UUID)om.insert("object_audit", JsonUtil.rhombusMapFromJsonMap(object,definition.getDefinitions().get("object_audit")), createdAt);

    //Update the object
    object.put("changes", null);
    om.update("object_audit", id, JsonUtil.rhombusMapFromJsonMap(object,definition.getDefinitions().get("object_audit")));

    //Get back the data and make sure things match
    Map<String, Object> result = om.getByKey("object_audit", id);
    assertNotNull(result);
    assertEquals(null, result.get("changes"));

    cm.teardown();
  }
View Full Code Here

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

    //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);
    ObjectMapper om = cm.getObjectMapper();
    om.setLogCql(true);

    //Insert our test data
    Map<String, Object> values = Maps.newHashMap();
    values.put("account_id", "00000003-0000-0030-0040-000000030000");
    values.put("object_type", "Account");
    values.put("object_id", "00000003-0000-0030-0040-000000030000");
    values.put("source_type", null);
    values.put("source_id", null);
    values.put("user_id", null);
    values.put("changes", "{\"Website\":{\"f\":\"http://www.somesite1.com\",\"t\":\"http://www.somesite2.com\"}}");

    UUID id = UUIDs.timeBased();
    om.update("object_audit", id, JsonUtil.rhombusMapFromJsonMap(values,definition.getDefinitions().get("object_audit")));

    //Get back the data and make sure things match
    Map<String, Object> result = om.getByKey("object_audit", id);
    assertNotNull(result);
    assertEquals("Account", result.get("object_type"));

    cm.teardown();
  }
View Full Code Here

  @Test
  public void testInsertAsync() 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);
    ObjectMapper om = cm.getObjectMapper();
    om.setExecuteAsync(true);

    //Insert our test data
    List<Map<String, Object>> values = JsonUtil.rhombusMapFromResource(this.getClass().getClassLoader(), "DateRangeQueryTestData.js");
    for(Map<String, Object> object : values) {
      Long createdAt = (Long)(object.get("created_at"));
      logger.debug("Inserting audit with created_at: {}", createdAt);
      om.insert("object_audit", JsonUtil.rhombusMapFromJsonMap(object,definition.getDefinitions().get("object_audit")), createdAt);
    }

    cm.teardown();
  }
View Full Code Here

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

    //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);
    ObjectMapper om = cm.getObjectMapper();
    om.setExecuteAsync(false);

    //Insert our test data
    List<Map<String, Object>> values = JsonUtil.rhombusMapFromResource(this.getClass().getClassLoader(), "DateRangeQueryTestData.js");
    for(Map<String, Object> object : values) {
      Long createdAt = (Long)(object.get("created_at"));
      logger.debug("Inserting audit with created_at: {}", createdAt);
      om.insert("object_audit", JsonUtil.rhombusMapFromJsonMap(object,definition.getDefinitions().get("object_audit")), createdAt);
    }

    cm.teardown();
  }
View Full Code Here

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

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

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

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

    // Do some inserts, making sure that each one will have to prepare a new statement
    List<Map<String, Object>> allInserts = Lists.newArrayList();
    Map<String, Object> toInsert;
    int minField = 0;
    int maxField = 12;
    for(int i = minField ; i <= maxField ; i++) {
      toInsert = Maps.newHashMap();
      toInsert.put("field" + i, "value" + i);
      allInserts.add(toInsert);
      for(int j = maxField ; j > i ; j--) {
        toInsert = Maps.newHashMap();
        toInsert.put("field" + i, "value" + i);
        for(int k = i+1 ; k <= j ; k++) {
          toInsert.put("field" + k, "value" + k);
        }
        allInserts.add(toInsert);
      }
    }

    for(Map<String, Object> insert : allInserts) {
      logger.warn("Inserting {}", insert);
      om.insert("simpletype", insert);
    }

    logger.warn("Successfully inserted {} records where each required a new prepare", allInserts.size());

    //Teardown connections
    cm.teardown();
  }
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.