|
|
|
@ -108,8 +108,17 @@ TEST_F(GeoDBTest, Search) { |
|
|
|
|
ASSERT_EQ(iter1->geo_object().value, "midvalue1"); |
|
|
|
|
uint32_t size = 0; |
|
|
|
|
while (iter1->Valid()) { |
|
|
|
|
GeoObject obj; |
|
|
|
|
status = getdb()->GetById(Slice(id1), &obj); |
|
|
|
|
ASSERT_TRUE(status.ok()); |
|
|
|
|
ASSERT_EQ(iter1->geo_object().position.latitude, pos1.latitude); |
|
|
|
|
ASSERT_EQ(iter1->geo_object().position.longitude, pos1.longitude); |
|
|
|
|
ASSERT_EQ(iter1->geo_object().id.compare(id1), 0); |
|
|
|
|
ASSERT_EQ(iter1->geo_object().value, value1); |
|
|
|
|
|
|
|
|
|
size++; |
|
|
|
|
iter1->Next(); |
|
|
|
|
ASSERT_TRUE(!iter1->Valid()); |
|
|
|
|
} |
|
|
|
|
ASSERT_EQ(size, 1U); |
|
|
|
|
delete iter1; |
|
|
|
@ -122,6 +131,57 @@ TEST_F(GeoDBTest, Search) { |
|
|
|
|
delete iter2; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(GeoDBTest, DifferentPosInSameQuadkey) { |
|
|
|
|
// insert obj1 into database
|
|
|
|
|
GeoPosition pos1(40.00001, 116.00001); |
|
|
|
|
std::string id1("12"); |
|
|
|
|
std::string value1("value1"); |
|
|
|
|
|
|
|
|
|
GeoObject obj1(pos1, id1, value1); |
|
|
|
|
Status status = getdb()->Insert(obj1); |
|
|
|
|
ASSERT_TRUE(status.ok()); |
|
|
|
|
|
|
|
|
|
// insert obj2 into database
|
|
|
|
|
GeoPosition pos2(40.00002, 116.00002); |
|
|
|
|
std::string id2("123"); |
|
|
|
|
std::string value2 = "value2"; |
|
|
|
|
|
|
|
|
|
GeoObject obj2(pos2, id2, value2); |
|
|
|
|
status = getdb()->Insert(obj2); |
|
|
|
|
ASSERT_TRUE(status.ok()); |
|
|
|
|
|
|
|
|
|
// get obj1's quadkey
|
|
|
|
|
ReadOptions opt; |
|
|
|
|
PinnableSlice quadkey1; |
|
|
|
|
status = getdb()->Get(opt, getdb()->DefaultColumnFamily(), "k:" + id1, &quadkey1); |
|
|
|
|
ASSERT_TRUE(status.ok()); |
|
|
|
|
|
|
|
|
|
// get obj2's quadkey
|
|
|
|
|
PinnableSlice quadkey2; |
|
|
|
|
status = getdb()->Get(opt, getdb()->DefaultColumnFamily(), "k:" + id2, &quadkey2); |
|
|
|
|
ASSERT_TRUE(status.ok()); |
|
|
|
|
|
|
|
|
|
// obj1 and obj2 have the same quadkey
|
|
|
|
|
ASSERT_EQ(quadkey1, quadkey2); |
|
|
|
|
|
|
|
|
|
// get obj1 by id, and check value
|
|
|
|
|
GeoObject obj; |
|
|
|
|
status = getdb()->GetById(Slice(id1), &obj); |
|
|
|
|
ASSERT_TRUE(status.ok()); |
|
|
|
|
ASSERT_EQ(obj.position.latitude, pos1.latitude); |
|
|
|
|
ASSERT_EQ(obj.position.longitude, pos1.longitude); |
|
|
|
|
ASSERT_EQ(obj.id.compare(id1), 0); |
|
|
|
|
ASSERT_EQ(obj.value, value1); |
|
|
|
|
|
|
|
|
|
// get obj2 by id, and check value
|
|
|
|
|
status = getdb()->GetById(Slice(id2), &obj); |
|
|
|
|
ASSERT_TRUE(status.ok()); |
|
|
|
|
ASSERT_EQ(obj.position.latitude, pos2.latitude); |
|
|
|
|
ASSERT_EQ(obj.position.longitude, pos2.longitude); |
|
|
|
|
ASSERT_EQ(obj.id.compare(id2), 0); |
|
|
|
|
ASSERT_EQ(obj.value, value2); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} // namespace rocksdb
|
|
|
|
|
|
|
|
|
|
int main(int argc, char* argv[]) { |
|
|
|
|