예제 #1
0
def save_and_get_complex():
	'''Test saving entities containing mapped collection properties'''
	entity1 = TestEntities.ComplexEntity()
	entity1.setId("complex1")
	strings = ArrayList()
	strings.add("one")
	strings.add("two")
	entity1.setStringList(strings)
	ints = HashSet()
	ints.add(1)
	ints.add(2)
	entity1.setIntSet(ints)
	extended = HashMap()
	extended.put("prop1", "one")
	extended.put("prop2", "two")
	entity1.setExtendedProps(extended)
	
	service = EntityService(TestEntities.ComplexEntity)
	service.save(entity1)
	
	entity2 = service.get("complex1")
	assertNotNull(entity2)
	assertEquals(entity2.getId(), entity1.getId())
	assertTrue(entity2.getStringList().contains("one"))
	assertTrue(entity2.getStringList().contains("two"))
	assertTrue(entity2.getIntSet().contains(java.lang.Long(1)))
	assertTrue(entity2.getIntSet().contains(java.lang.Long(2)))
	assertNotNull(entity2.getExtendedProps())
	assertEquals(entity2.getExtendedProps().get("prop1"), "one")
	assertEquals(entity2.getExtendedProps().get("prop2"), "two")
예제 #2
0
def save_and_get_complex():
    '''Test saving entities containing mapped collection properties'''
    entity1 = TestEntities.ComplexEntity()
    entity1.setId("complex1")
    strings = ArrayList()
    strings.add("one")
    strings.add("two")
    entity1.setStringList(strings)
    ints = HashSet()
    ints.add(1)
    ints.add(2)
    entity1.setIntSet(ints)
    extended = HashMap()
    extended.put("prop1", "one")
    extended.put("prop2", "two")
    entity1.setExtendedProps(extended)

    service = EntityService(TestEntities.ComplexEntity)
    service.save(entity1)

    entity2 = service.get("complex1")
    assertNotNull(entity2)
    assertEquals(entity2.getId(), entity1.getId())
    assertTrue(entity2.getStringList().contains("one"))
    assertTrue(entity2.getStringList().contains("two"))
    assertTrue(entity2.getIntSet().contains(java.lang.Long(1)))
    assertTrue(entity2.getIntSet().contains(java.lang.Long(2)))
    assertNotNull(entity2.getExtendedProps())
    assertEquals(entity2.getExtendedProps().get("prop1"), "one")
    assertEquals(entity2.getExtendedProps().get("prop2"), "two")
예제 #3
0
def save_and_get():
	entity1 = TestEntities.SimpleEntity()
	entity1.setId("entity1")
	entity1.setStringProperty("all my words")
	entity1.setIntProperty(123)
	entity1.setFloatProperty(1.1)
	entity1.setDoubleProperty(123.456789)
	entity1.setLongProperty(444444444444)

	service = EntityService(TestEntities.SimpleEntity)
	service.save(entity1)

	entity2 = service.get("entity1")
	assertNotNull(entity2)
	assertEquals(entity2.getId(), entity1.getId())
	assertEquals(entity2.getStringProperty(), entity1.getStringProperty())
	assertEquals(entity2.getIntProperty(), entity1.getIntProperty())
	assertEquals(entity2.getFloatProperty(), entity1.getFloatProperty(), None, 0.0001)
	assertEquals(entity2.getDoubleProperty(), entity1.getDoubleProperty(), None, 0.0001)
	assertEquals(entity2.getLongProperty(), entity1.getLongProperty())

	# update the retrieved entity and check for the changes
	entity2.setStringProperty("new stuff")
	entity2.setDoubleProperty(9.8765432101)
	entity2.setIntProperty(-17)
	service.save(entity2)
	
	entity3 = service.get(entity2.getId())
	assertEquals(entity3.getId(), "entity1")
	assertEquals(entity3.getStringProperty(), "new stuff")
	assertEquals(entity3.getIntProperty(), -17)
	assertEquals(entity3.getFloatProperty(), 1.1, None, 0.0001)
	assertEquals(entity3.getDoubleProperty(), 9.8765432101, None, 0.0001)
	assertEquals(entity3.getLongProperty(), 444444444444)
예제 #4
0
def save_timeout():
    '''Test timeouts when saving recs'''
    newent = TestEntities.SimpleEntity("ne1", "string one", 1, 1.1, 1.1, 1)
    service = EntityService(TestEntities.SimpleEntity)
    try:
        # save with too short timeout
        success = service.save(newent, 1)
        assertFalse(success, "Expected save request to timeout")
    except HBaseException, e:
        fail("Save failed with unexpected exception")
예제 #5
0
def save_timeout():
	'''Test timeouts when saving recs'''
	newent = TestEntities.SimpleEntity("ne1", "string one", 1, 1.1, 1.1, 1);
	service = EntityService(TestEntities.SimpleEntity)
	try:
		# save with too short timeout
		success = service.save(newent, 1)
		assertFalse(success, "Expected save request to timeout")
	except HBaseException, e:
		fail("Save failed with unexpected exception")
예제 #6
0
def save_and_get():
    entity1 = TestEntities.SimpleEntity()
    entity1.setId("entity1")
    entity1.setStringProperty("all my words")
    entity1.setIntProperty(123)
    entity1.setFloatProperty(1.1)
    entity1.setDoubleProperty(123.456789)
    entity1.setLongProperty(444444444444)

    service = EntityService(TestEntities.SimpleEntity)
    service.save(entity1)

    entity2 = service.get("entity1")
    assertNotNull(entity2)
    assertEquals(entity2.getId(), entity1.getId())
    assertEquals(entity2.getStringProperty(), entity1.getStringProperty())
    assertEquals(entity2.getIntProperty(), entity1.getIntProperty())
    assertEquals(entity2.getFloatProperty(), entity1.getFloatProperty(), None,
                 0.0001)
    assertEquals(entity2.getDoubleProperty(), entity1.getDoubleProperty(),
                 None, 0.0001)
    assertEquals(entity2.getLongProperty(), entity1.getLongProperty())

    # update the retrieved entity and check for the changes
    entity2.setStringProperty("new stuff")
    entity2.setDoubleProperty(9.8765432101)
    entity2.setIntProperty(-17)
    service.save(entity2)

    entity3 = service.get(entity2.getId())
    assertEquals(entity3.getId(), "entity1")
    assertEquals(entity3.getStringProperty(), "new stuff")
    assertEquals(entity3.getIntProperty(), -17)
    assertEquals(entity3.getFloatProperty(), 1.1, None, 0.0001)
    assertEquals(entity3.getDoubleProperty(), 9.8765432101, None, 0.0001)
    assertEquals(entity3.getLongProperty(), 444444444444)
예제 #7
0
def setup():
    hc.setUp()
    HUtil.setPool( HTablePool( hc.conf, 5 ) )
    # create a dummy HBase table for testing
    import db.hbase
    admin = db.hbase.Admin(hc.conf)

    if not admin.exists("test_indexed"):
        admin.create("test_indexed", {"props:": {}})	
    if not admin.exists("test_indexed-by_intcol"):
        admin.create("test_indexed-by_intcol", {"props:": {}, "__idx__:": {}})
    if not admin.exists("test_indexed-by_stringcol"):
        admin.create("test_indexed-by_stringcol", {"props:": {}, "__idx__:": {}})

    srv = EntityService(TestEntities.IndexedEntity)
    now = java.lang.System.currentTimeMillis()

    srv.save( TestEntities.IndexedEntity("e1", "duck", 1, now - 100) )
    srv.save( TestEntities.IndexedEntity("e2", "duck", 2, now - 80) )
    srv.save( TestEntities.IndexedEntity("e3", "duck", 2, now - 60) )
    srv.save( TestEntities.IndexedEntity("e4", "goose", 2, now - 40) )
예제 #8
0
def setup():
    hc.setUp()
    HUtil.setPool(HTablePool(hc.conf, 5))
    # create a dummy HBase table for testing
    import db.hbase
    admin = db.hbase.Admin(hc.conf)

    if not admin.exists("test_indexed"):
        admin.create("test_indexed", {"props:": {}})
    if not admin.exists("test_indexed-by_intcol"):
        admin.create("test_indexed-by_intcol", {"props:": {}, "__idx__:": {}})
    if not admin.exists("test_indexed-by_stringcol"):
        admin.create("test_indexed-by_stringcol", {
            "props:": {},
            "__idx__:": {}
        })

    srv = EntityService(TestEntities.IndexedEntity)
    now = java.lang.System.currentTimeMillis()

    srv.save(TestEntities.IndexedEntity("e1", "duck", 1, now - 100))
    srv.save(TestEntities.IndexedEntity("e2", "duck", 2, now - 80))
    srv.save(TestEntities.IndexedEntity("e3", "duck", 2, now - 60))
    srv.save(TestEntities.IndexedEntity("e4", "goose", 2, now - 40))