Package com.pardot.rhombus

Examples of com.pardot.rhombus.ConnectionManager


  @BeforeClass
  public static void setupKeyspace()
  {
    try {
      ConnectionManager cm = getConnectionManagerStatic();
      keyspaceDefinition = JsonUtil.objectFromJsonResource(CKeyspaceDefinition.class, ObjectMapperShardingITCase.class.getClassLoader(), "ShardedKeyspace.js");
      cm.buildKeyspace(keyspaceDefinition, true);
    } catch(Exception e) {
      throw new RuntimeException(e);
    }
  }
View Full Code Here


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

    // Get an object mapper for the keyspace and truncate the data
    ConnectionManager cm = getConnectionManager();
    ObjectMapper om = cm.getObjectMapper(keyspaceDefinition);
    om.truncateTables();
    om.setLogCql(true);

    //Set up test data
    List<Map<String, Object>> values = JsonUtil.rhombusMapFromResource(this.getClass().getClassLoader(), "ShardedTestData.js");
    for(Map<String, Object> object : values) {
      Map<String, Object> updatedObject = JsonUtil.rhombusMapFromJsonMap(object, keyspaceDefinition.getDefinitions().get("object1"));
      Long createdAt = ((Date)(updatedObject.get("created_at"))).getTime();
      logger.debug("Inserting object with created_at: {}", createdAt);
      UUID id = (UUID)om.insert("object1", updatedObject, createdAt);
      logger.debug("Inserted object with uuid unix time: {}", UUIDs.unixTimestamp(id));
    }

    //Query it back out
    //Make sure that we have the proper number of results
    SortedMap<String, Object> indexValues = Maps.newTreeMap();
    indexValues.put("account_id", UUID.fromString("00000003-0000-0030-0040-000000030000"));
    indexValues.put("user_id", UUID.fromString("00000003-0000-0030-0040-000000030000"));
    Criteria criteria = new Criteria();
    criteria.setIndexKeys(indexValues);
    criteria.setLimit(50L);
    List<Map<String, Object>> results = om.list("object1", criteria);
    assertEquals(3, results.size());

    cm.teardown();
  }
View Full Code Here

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

    // Get an object mapper for the keyspace and truncate the data
    ConnectionManager cm = getConnectionManager();
    ObjectMapper om = cm.getObjectMapper(keyspaceDefinition);
    om.truncateTables();
    om.setLogCql(true);

    // Insert a record that is more than ObjectMapper.reasonableStatementLimit months old
    DateTime dateTime = DateTime.now().minusMonths(om.getReasonableStatementLimit() * 2);
    UUID id = UUIDs.startOf(dateTime.getMillis());
    UUID accountId = UUID.fromString("00000003-0000-0030-0040-000000030000");
    UUID userId = UUID.fromString("00000003-0000-0030-0040-000000030000");
    Map<String, Object> record = Maps.newHashMap();
    record.put("id", id);
    record.put("account_id", accountId);
    record.put("user_id", userId);
    om.insert("object1", record);

    //Query it back out, make sure that we are using the shard index, because if we are not, we will surpass reasonable statement limit
    SortedMap<String, Object> indexValues = Maps.newTreeMap();
    indexValues.put("account_id", accountId);
    indexValues.put("user_id", userId);
    Criteria criteria = new Criteria();
    criteria.setIndexKeys(indexValues);
    criteria.setEndTimestamp(DateTime.now().getMillis());
    criteria.setLimit(50L);
    List<Map<String, Object>> results = om.list("object1", criteria);

    assertEquals(1, results.size());

    cm.teardown();
  }
View Full Code Here

  UUID userId = UUIDs.random();

  @Test
  public void testGetLessThanLimitInSingleShard() throws Exception {
    //Build the connection manager
    ConnectionManager cm = getConnectionManager();
    cm.setLogCql(true);

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

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

    long insertNum = 10l;

    insertNObjects(om, insertNum, null);

    // Get 50 back
    long limit = 50l;
    Criteria criteria = new Criteria();
    SortedMap<String, Object> indexKeys = Maps.newTreeMap();
    indexKeys.put("account_id", accountId);
    indexKeys.put("user_id", userId);
    criteria.setIndexKeys(indexKeys);
    criteria.setLimit(limit);
    List<Map<String, Object>> results = om.list(objectType, criteria);

    assertEquals(insertNum, results.size());

    cm.teardown();
  }
View Full Code Here

  }

  @Test
  public void testGetInEmptyShardList() throws Exception {
    //Build the connection manager
    ConnectionManager cm = getConnectionManager();
    cm.setLogCql(true);

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

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

    // Get 50 back
    long limit = 50l;
    Criteria criteria = new Criteria();
    SortedMap<String, Object> indexKeys = Maps.newTreeMap();
    indexKeys.put("account_id", accountId);
    indexKeys.put("user_id", userId);
    criteria.setIndexKeys(indexKeys);
    criteria.setLimit(limit);
    List<Map<String, Object>> results = om.list(objectType, criteria);

    assertEquals(0, results.size());

    cm.teardown();
  }
View Full Code Here

  }

  @Test
  public void testInsertWithIdsAndGet() throws Exception {
    //Build the connection manager
    ConnectionManager cm = getConnectionManager();
    cm.setLogCql(true);

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

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

    long insertNum = 18l;

    List<UUID> idList = Lists.newArrayList();
    for(int i = 0 ; i < insertNum ; i++) {
      idList.add(UUIDs.timeBased());
    }

    insertNObjects(om, insertNum, idList);

    // Get 50 back
    long limit = 50l;
    Criteria criteria = new Criteria();
    SortedMap<String, Object> indexKeys = Maps.newTreeMap();
    indexKeys.put("account_id", accountId);
    indexKeys.put("user_id", userId);
    criteria.setIndexKeys(indexKeys);
    criteria.setLimit(limit);
    List<Map<String, Object>> results = om.list(objectType, criteria);

    assertEquals(insertNum, results.size());

    for(UUID id : idList) {
      assertTrue(resultsContainId(results, id));
    }

    cm.teardown();
  }
View Full Code Here

  }

  @Test
  public void testInsert2WithIdsAcrossShardsAndGet() throws Exception {
    //Build the connection manager
    ConnectionManager cm = getConnectionManager();
    cm.setLogCql(true);

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

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

    long insertNum = 2l;

    List<UUID> idList = Lists.newArrayList();
    idList.add(UUID.fromString("7dcf8c00-bcc1-11e2-8080-808080808080"));
    idList.add(UUID.fromString("6d554c00-61ce-11e2-8080-808080808080"));

    insertNObjects(om, insertNum, idList);

    // Get 50 back
    long limit = 50l;
    Criteria criteria = new Criteria();
    SortedMap<String, Object> indexKeys = Maps.newTreeMap();
    indexKeys.put("account_id", accountId);
    indexKeys.put("user_id", userId);
    criteria.setIndexKeys(indexKeys);
    criteria.setLimit(limit);
    List<Map<String, Object>> results = om.list(objectType, criteria);

    assertEquals(insertNum, results.size());

    for(UUID id : idList) {
      assertTrue(resultsContainId(results, id));
    }

    cm.teardown();
  }
View Full Code Here

  }

  @Test
  public void testInsert18WithIdsAcrossShardsAndGet() throws Exception {
    //Build the connection manager
    ConnectionManager cm = getConnectionManager();
    cm.setLogCql(true);

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

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

    long insertNum = 18l;

    List<UUID> idList = Lists.newArrayList();
    idList.add(UUID.fromString("7dcf8c00-bcc1-11e2-8080-808080808080"));
    idList.add(UUID.fromString("d1db7000-bcc3-11e2-8080-808080808080"));
    idList.add(UUID.fromString("25e75400-bcc6-11e2-8080-808080808080"));
    idList.add(UUID.fromString("79f33800-bcc8-11e2-8080-808080808080"));
    idList.add(UUID.fromString("cdff1c00-bcca-11e2-8080-808080808080"));
    idList.add(UUID.fromString("220b0000-bccd-11e2-8080-808080808080"));
    idList.add(UUID.fromString("7616e400-bccf-11e2-8080-808080808080"));
    idList.add(UUID.fromString("ca22c800-bcd1-11e2-8080-808080808080"));
    idList.add(UUID.fromString("1e2eac00-bcd4-11e2-8080-808080808080"));
    idList.add(UUID.fromString("723a9000-bcd6-11e2-8080-808080808080"));
    idList.add(UUID.fromString("c6467400-bcd8-11e2-8080-808080808080"));
    idList.add(UUID.fromString("f1a16400-bbef-11e2-8080-808080808080"));
    idList.add(UUID.fromString("48574400-ba1e-11e2-8080-808080808080"));
    idList.add(UUID.fromString("5cff6400-9ed5-11e2-8080-808080808080"));
    idList.add(UUID.fromString("3ffb0000-a496-11e2-8080-808080808080"));
    idList.add(UUID.fromString("1d2cc000-8c3a-11e2-8080-808080808080"));
    idList.add(UUID.fromString("799bc000-7639-11e2-8080-808080808080"));
    idList.add(UUID.fromString("6d554c00-61ce-11e2-8080-808080808080"));

    insertNObjects(om, insertNum, idList);

    // Get 50 back
    long limit = 50l;
    Criteria criteria = new Criteria();
    SortedMap<String, Object> indexKeys = Maps.newTreeMap();
    indexKeys.put("account_id", accountId);
    indexKeys.put("user_id", userId);
    criteria.setIndexKeys(indexKeys);
    criteria.setLimit(limit);
    List<Map<String, Object>> results = om.list(objectType, criteria);

    assertEquals(insertNum, results.size());

    for(UUID id : idList) {
      assertTrue(resultsContainId(results, id));
    }

    cm.teardown();
  }
View Full Code Here

  }

  @Test
  public void testInsert18WithIdsAcrossShardsAndCount() throws Exception {
    //Build the connection manager
    ConnectionManager cm = getConnectionManager();
    cm.setLogCql(true);

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

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

    long insertNum = 18l;

    List<UUID> idList = Lists.newArrayList();
    idList.add(UUID.fromString("7dcf8c00-bcc1-11e2-8080-808080808080"));
    idList.add(UUID.fromString("d1db7000-bcc3-11e2-8080-808080808080"));
    idList.add(UUID.fromString("25e75400-bcc6-11e2-8080-808080808080"));
    idList.add(UUID.fromString("79f33800-bcc8-11e2-8080-808080808080"));
    idList.add(UUID.fromString("cdff1c00-bcca-11e2-8080-808080808080"));
    idList.add(UUID.fromString("220b0000-bccd-11e2-8080-808080808080"));
    idList.add(UUID.fromString("7616e400-bccf-11e2-8080-808080808080"));
    idList.add(UUID.fromString("ca22c800-bcd1-11e2-8080-808080808080"));
    idList.add(UUID.fromString("1e2eac00-bcd4-11e2-8080-808080808080"));
    idList.add(UUID.fromString("723a9000-bcd6-11e2-8080-808080808080"));
    idList.add(UUID.fromString("c6467400-bcd8-11e2-8080-808080808080"));
    idList.add(UUID.fromString("f1a16400-bbef-11e2-8080-808080808080"));
    idList.add(UUID.fromString("48574400-ba1e-11e2-8080-808080808080"));
    idList.add(UUID.fromString("5cff6400-9ed5-11e2-8080-808080808080"));
    idList.add(UUID.fromString("3ffb0000-a496-11e2-8080-808080808080"));
    idList.add(UUID.fromString("1d2cc000-8c3a-11e2-8080-808080808080"));
    idList.add(UUID.fromString("799bc000-7639-11e2-8080-808080808080"));
    idList.add(UUID.fromString("6d554c00-61ce-11e2-8080-808080808080"));

    insertNObjects(om, insertNum, idList);

    Criteria criteria = new Criteria();
    SortedMap<String, Object> indexKeys = Maps.newTreeMap();
    indexKeys.put("account_id", accountId);
    indexKeys.put("user_id", userId);
    criteria.setIndexKeys(indexKeys);

    long count = om.count(objectType, criteria);
    assertEquals(insertNum, count);

    cm.teardown();
  }
View Full Code Here

  }

  @Test
  public void testInsert18WithIdsAcrossShardsAndCountWithFiltering() throws Exception {
    //Build the connection manager
    ConnectionManager cm = getConnectionManager();
    cm.setLogCql(true);

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

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

    long insertNum = 18l;

    List<UUID> idList = Lists.newArrayList();
    idList.add(UUID.fromString("7dcf8c00-bcc1-11e2-8080-808080808080"));
    idList.add(UUID.fromString("d1db7000-bcc3-11e2-8080-808080808080"));
    idList.add(UUID.fromString("25e75400-bcc6-11e2-8080-808080808080"));
    idList.add(UUID.fromString("79f33800-bcc8-11e2-8080-808080808080"));
    idList.add(UUID.fromString("cdff1c00-bcca-11e2-8080-808080808080"));
    idList.add(UUID.fromString("220b0000-bccd-11e2-8080-808080808080"));
    idList.add(UUID.fromString("7616e400-bccf-11e2-8080-808080808080"));
    idList.add(UUID.fromString("ca22c800-bcd1-11e2-8080-808080808080"));
    idList.add(UUID.fromString("1e2eac00-bcd4-11e2-8080-808080808080"));
    idList.add(UUID.fromString("723a9000-bcd6-11e2-8080-808080808080"));
    idList.add(UUID.fromString("c6467400-bcd8-11e2-8080-808080808080"));
    idList.add(UUID.fromString("f1a16400-bbef-11e2-8080-808080808080"));
    idList.add(UUID.fromString("48574400-ba1e-11e2-8080-808080808080"));
    idList.add(UUID.fromString("5cff6400-9ed5-11e2-8080-808080808080"));
    idList.add(UUID.fromString("3ffb0000-a496-11e2-8080-808080808080"));
    idList.add(UUID.fromString("1d2cc000-8c3a-11e2-8080-808080808080"));
    idList.add(UUID.fromString("799bc000-7639-11e2-8080-808080808080"));
    idList.add(UUID.fromString("6d554c00-61ce-11e2-8080-808080808080"));

    insertNObjects(om, insertNum, idList);

    Map<String, Object> object = Maps.newHashMap();
    object.put("id", UUIDs.timeBased());
    object.put("account_id", accountId);
    object.put("user_id", UUIDs.random());
    om.insert(objectType, object);

    Criteria criteria = new Criteria();
    SortedMap<String, Object> indexKeys = Maps.newTreeMap();
    indexKeys.put("account_id", accountId);
    indexKeys.put("user_id", userId);
    criteria.setIndexKeys(indexKeys);

    long count = om.count(objectType, criteria);
    assertEquals(insertNum, count);

    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.