def testGetDelta(self): d0 = TestDesign.designFactory() d1 = TestDesign.designFactory() delta = d0.getDelta(d0) self.assertEqual(0, len(delta)) delta = d0.getDelta(d1) self.assertEqual(0, len(delta)) d2 = design.Design() for col_name in d0.getCollections(): d2.addCollection(col_name) d2.addShardKey(col_name, d0.getShardKeys(col_name)) for indexKeys in d0.getIndexes(col_name): d2.addIndex(col_name, indexKeys) break delta = d0.getDelta(d2) self.assertEqual(1, len(delta)) # Throw an empty design at it. All of the collections # should come back in our delta d3 = design.Design() delta = d0.getDelta(d3) self.assertEquals(d0.getCollections(), delta)
def testAddIndex(self) : d = design.Design() collection = 'test 1' index = ('field 1', 'field 2') d.addCollection(collection) d.addIndex(collection, index) self.assertListEqual(d.getIndexes(collection), [index])
def testAddShardKey(self) : d = design.Design() collection = 'test' key = ['field 1'] d.addCollection(collection) d.addShardKey(collection, key) self.assertEqual(d.getShardKeys(collection), key)
def testGetDenormalizationHierarchy(self): # Dependency Tree # A # / \ # B C # | # D expected = { 'A': [ ], 'B': ['A'], 'C': ['A'], 'D': ['A', 'B'] } d = design.Design() d.addCollections(expected.keys()) d.setDenormalizationParent('B', 'A') d.setDenormalizationParent('C', 'A') d.setDenormalizationParent('D', 'B') print d for collection in d.getCollections(): hierarchy = d.getDenormalizationHierarchy(collection) #print "-"*50 #print collection, hierarchy self.assertNotEqual(hierarchy, None) self.assertTrue(collection in expected) self.assertEqual(expected[collection], hierarchy)
def testGetParentCollection(self): d = design.Design() d.addCollection('A') d.addCollection('B') d.setDenormalizationParent('B', 'A') self.assertFalse(d.isDenormalized('A')) self.assertTrue(d.isDenormalized('B')) self.assertEqual('A', d.getDenormalizationParent('B'))
def testAddShardKeys(self) : d = design.Design() collections = ['test 1', 'test 2'] d.addCollections(collections) keys = {} for col in collections : keys[col] = ['field 1'] d.addShardKeys(keys) self.assertEqual(d.getAllShardKeys(), keys)
def designFactory(): d = design.Design() collections = ['col 1', 'col 2'] d.addCollections(collections) d.addShardKey('col 1', ['c1b']) d.addShardKey('col 2', ['c2a']) d.addIndex('col 1', ['c1a']) d.addIndex('col 2', ['c2c']) d.addIndex('col 2', ['c2a', 'c2d']) return d
def setUp(self): self.initialDesign = design.Design() self.initialDesign.addCollection("col1") self.initialDesign.addCollection("col2") self.initialDesign.reset("col1") self.initialDesign.reset("col2") self.upper_bound = 1 self.timeout = 1000000000 def dummy_bounding_f(design): return (0) self.costmodel = DummyCostModel(dummy_bounding_f)
def testBBSearch_timeoutTest(): print("\n\n === BBSerch Timeout Test === \n") # cost function takes 1 sec... therefore, there should be about 10 nodes after 10 sec def slow_bounding_f(design): time.sleep(1) return 0 initialDesign = design.Design() upper_bound = 1 timeout = 5 costmodel = DummyCostModel(slow_bounding_f) dc = designcandidate.DesignCandidate() dc.addCollection("col1", [], ["key1", "key2", "key3"], []) dc.addCollection("col2", [], ["field1", "field2"], []) bb = bbsearch.BBSearch(dc, costmodel, initialDesign, upper_bound, timeout) bb.solve() nodeList = bb.listAllNodes()
def testAddCollections(self) : d = design.Design() collections = ['Test 1', 'Test 2'] d.addCollections(collections) self.assertEqual(sorted(d.getCollections()), sorted(collections))
def testAddCollection(self) : d = design.Design() collection = 'Test' d.addCollection(collection) self.assertEqual(d.getCollections(), [collection])
def testBBSearch1(): def dummy_bounding_f(design): return (0) initialDesign = design.Design() upper_bound = 1 timeout = 1000000000 costmodel = DummyCostModel(dummy_bounding_f) ''' dummy example: since the bounding function returns always float('inf'), this should basically traverse the entire tree --> this test verifies that bbsearch does not omit any nodes ''' print("\n\n === BBSearch Simple Test - empty === \n") dc = designcandidate.DesignCandidate() dc.addCollection("col1", [], [], []) dc.addCollection("col2", [], [], []) bb = bbsearch.BBSearch(dc, costmodel, initialDesign, upper_bound, timeout) bb.solve() nodeList = bb.listAllNodes() ''' now the some with shard keys... ''' print("\n\n === BBSearch Simple Test - shard keys === \n") dc = designcandidate.DesignCandidate() dc.addCollection("col1", [], [], []) dc.addCollection("col2", [], ["key1", "key2"], []) #same as above, just 4 time more leaf nodes, since c1 can be sharded on k1..3,None bb = bbsearch.BBSearch(dc, costmodel, initialDesign, upper_bound, timeout) bb.solve() nodeList = bb.listAllNodes() print("\n\n === BBSearch Simple Test - more shard keys === \n") dc = designcandidate.DesignCandidate() dc.addCollection("col1", [], ["f1", "f2"], []) dc.addCollection("col2", [], ["key2", "key3"], []) #same as above, just 4 time more leaf nodes, since c1 can be sharded on k1..3,None bb = bbsearch.BBSearch(dc, costmodel, initialDesign, upper_bound, timeout) bb.solve() nodeList = bb.listAllNodes() ''' now with some indexes... ''' print("\n\n === BBSearch Simple Test - indexes === \n") dc = designcandidate.DesignCandidate() dc.addCollection("col1", [], [], []) dc.addCollection("col2", [("key1"), ("key1", "key2"), ("key1", "key3")], [], []) #same as above, just 4 time more leaf nodes, since c1 can be sharded on k1..3,None bb = bbsearch.BBSearch(dc, costmodel, initialDesign, upper_bound, timeout) bb.solve() nodeList = bb.listAllNodes() ''' now with some denorm... ''' print("\n\n === BBSearch Simple Test - denorm === \n") dc = designcandidate.DesignCandidate() dc.addCollection("col1", [], [], ["col2"]) dc.addCollection("col2", [], [], ["col1"]) #same as above, just 4 time more leaf nodes, since c1 can be sharded on k1..3,None bb = bbsearch.BBSearch(dc, costmodel, initialDesign, upper_bound, timeout) bb.solve() nodeList = bb.listAllNodes()