def test_furthest_on_single_w_miss(self): CONFIG.unmap_bs("rootbs") CONFIG.remove_bs(self.bspath) self.bs = utp.BlockStore.create(CONFIG.BSTYPE, "rootbs", CONFIG.BSSIZE, CONFIG.BSARGS(self.bspath)) # Insert a single SHE. node = utp.SignedHeadEdge(("fsid", "rootref", 0, time.time() * 1e6, 0, 0)) self.bs.bs_head_insert(node) # Furthest should miss w/ bad key. miss = (buffer("fsid"), buffer("notref")) shes = self.bs.bs_head_furthest(miss) assert lenhack(shes) == 0 # Reopen the blockstore. self.bs.bs_close() self.bs = utp.BlockStore.open(CONFIG.BSTYPE, "rootbs", CONFIG.BSARGS(self.bspath)) # Furthest should miss w/ bad key. miss = (buffer("fsid"), buffer("notref")) shes = self.bs.bs_head_furthest(miss) assert lenhack(shes) == 0 # Close the blockstore. self.bs.bs_close() CONFIG.remove_bs(self.bspath)
def test_furthest_on_single(self): CONFIG.unmap_bs("rootbs") CONFIG.remove_bs(self.bspath) self.bs = utp.BlockStore.create(CONFIG.BSTYPE, "rootbs", CONFIG.BSSIZE, CONFIG.BSARGS(self.bspath)) # Insert a single SHE. node = utp.SignedHeadEdge(("fsid", "rootref", 0, time.time() * 1e6, 0, 0)) self.bs.bs_head_insert(node) # Furthest should return the node we inserted. seed = (buffer("fsid"), buffer("")) shes = self.bs.bs_head_furthest(seed) assert lenhack(shes) == 1 assert shes[0] == (buffer("fsid"), buffer("rootref")) # Reopen the blockstore. self.bs.bs_close() self.bs = utp.BlockStore.open(CONFIG.BSTYPE, "rootbs", CONFIG.BSARGS(self.bspath)) # Furthest should return the node we inserted. seed = (buffer("fsid"), buffer("")) shes = self.bs.bs_head_furthest(seed) assert lenhack(shes) == 1 assert shes[0] == (buffer("fsid"), buffer("rootref")) # Close the blockstore. self.bs.bs_close() CONFIG.remove_bs(self.bspath)
def test_on_delta(self): print "Create first child." bspath1 = "vbs_head_04_c1" CONFIG.unmap_bs("child1") CONFIG.remove_bs(bspath1) self.bs1 = utp.BlockStore.create(CONFIG.BSTYPE, "child1", CONFIG.BSSIZE, CONFIG.BSARGS(bspath1)) # Insert a node into this child only node1 = utp.SignedHeadEdge(("fsid", "node1", 0, time.time() * 1e6, 0, 0)) self.bs1.bs_head_insert(node1) print " Create second child." bspath2 = "vbs_head_04_c2" CONFIG.unmap_bs("child2") CONFIG.remove_bs(bspath2) self.bs2 = utp.BlockStore.create(CONFIG.BSTYPE, "child2", CONFIG.BSSIZE, CONFIG.BSARGS(bspath2)) # Don't insert *anything* into this child. print "Open the virtual block store." CONFIG.unmap_bs("rootbs") self.vbs = utp.BlockStore.open("VBS", "rootbs", ("child1", "child2")) seed0 = (buffer("fsid"), buffer("")) # Further w/ empty should return all nodes. shes = self.vbs.bs_head_furthest(seed0) assert lenhack(shes) == 1 assert sorted(shes) == [ (buffer("fsid"), buffer("node1")), ] # Wait for synchronization to complete. self.vbs.bs_sync() # Further on second should return same result. shes = self.bs2.bs_head_furthest(seed0) assert lenhack(shes) == 1 assert sorted(shes) == [ (buffer("fsid"), buffer("node1")), ] print "Close for good." self.vbs.bs_close() self.vbs = None self.bs2.bs_close() self.bs2 = None self.bs1.bs_close() self.bs1 = None CONFIG.remove_bs(bspath2) CONFIG.remove_bs(bspath1)
def test_refresh_missing(self): # store 3 blocks for keystr in ('key1', 'key2', 'key3'): k = buffer(keystr) v = buffer("this phrase is also data") self.bs.bs_block_put(k, v) # refresh 1 of them and one that isn't there keys = (buffer('key2'), buffer('key4')) self.bs.bs_refresh_start(714) missing = self.bs.bs_refresh_blocks(714, keys) self.bs.bs_refresh_finish(714) assert lenhack(missing) == 1 assert missing[0] == buffer('key4')
def test_refresh_blocks(self): # store 3 blocks for keystr in ('key1', 'key2', 'key3'): k = buffer(keystr) v = buffer("this phrase is data") self.bs.bs_block_put(k, v) # refresh 2 of them keys = (buffer('key1'), buffer('key3')) self.bs.bs_refresh_start(42) missing = self.bs.bs_refresh_blocks(42, keys) self.bs.bs_refresh_finish(42) assert lenhack(missing) == 0
def test_two_nodes(self): self.bs = utp.BlockStore.create(CONFIG.BSTYPE, "rootbs", CONFIG.BSSIZE, CONFIG.BSARGS(self.bspath)) # Insert the first SHN. node1 = utp.SignedHeadEdge(("fsid", "node1", 0, time.time() * 1e6, 0, 0)) self.bs.bs_head_insert(node1) # Insert the second SHN. node2 = utp.SignedHeadEdge(("fsid", "node2", "node1", time.time() * 1e6, 0, 0)) self.bs.bs_head_insert(node2) # Furthest w/ empty should return the second node we inserted. seed0 = (buffer("fsid"), buffer("")) shes = self.bs.bs_head_furthest(seed0) assert lenhack(shes) == 1 assert shes[0] == (buffer("fsid"), buffer("node2")) # Furthest w/ first should return the second node we inserted. seed1 = (buffer("fsid"), buffer("node1")) shes = self.bs.bs_head_furthest(seed1) assert lenhack(shes) == 1 assert shes[0] == (buffer("fsid"), buffer("node2")) # Furthest w/ last should return the second node we inserted. seed2 = (buffer("fsid"), buffer("node2")) shes = self.bs.bs_head_furthest(seed2) assert lenhack(shes) == 1 assert shes[0] == (buffer("fsid"), buffer("node2")) # Follow w/ empty should return both nodes. shes = self.bs.bs_head_follow(seed0) assert lenhack(shes) == 2 assert str(shes[0].rootref) == "node1" assert str(shes[1].rootref) == "node2" # Follow w/ first should return the second node. shes = self.bs.bs_head_follow(seed1) assert lenhack(shes) == 1 assert str(shes[0].rootref) == "node2" # Follow w/ last should return nothing. shes = self.bs.bs_head_follow(seed2) assert lenhack(shes) == 0 # Reopen the blockstore. self.bs.bs_close() self.bs = utp.BlockStore.open(CONFIG.BSTYPE, "rootbs", CONFIG.BSARGS(self.bspath)) # Furthest w/ empty should return the second node we inserted. seed0 = (buffer("fsid"), buffer("")) shes = self.bs.bs_head_furthest(seed0) assert lenhack(shes) == 1 assert shes[0] == (buffer("fsid"), buffer("node2")) # Furthest w/ first should return the second node we inserted. seed1 = (buffer("fsid"), buffer("node1")) shes = self.bs.bs_head_furthest(seed1) assert lenhack(shes) == 1 assert shes[0] == (buffer("fsid"), buffer("node2")) # Furthest w/ last should return the second node we inserted. seed2 = (buffer("fsid"), buffer("node2")) shes = self.bs.bs_head_furthest(seed2) assert lenhack(shes) == 1 assert shes[0] == (buffer("fsid"), buffer("node2")) # Follow w/ empty should return both nodes. shes = self.bs.bs_head_follow(seed0) assert lenhack(shes) == 2 assert str(shes[0].rootref) == "node1" assert str(shes[1].rootref) == "node2" # Follow w/ first should return the second node. shes = self.bs.bs_head_follow(seed1) assert lenhack(shes) == 1 assert str(shes[0].rootref) == "node2" # Follow w/ last should return nothing. shes = self.bs.bs_head_follow(seed2) assert lenhack(shes) == 0 # Close the blockstore. self.bs.bs_close() CONFIG.remove_bs(self.bspath)
def test_on_empty(self): print "test_on_empty starting" # First child. bspath1 = "vbs_head_01_c1" CONFIG.unmap_bs("child1") CONFIG.remove_bs(bspath1) self.bs1 = utp.BlockStore.create(CONFIG.BSTYPE, "child1", CONFIG.BSSIZE, CONFIG.BSARGS(bspath1)) # Second child. bspath2 = "vbs_head_01_c2" CONFIG.unmap_bs("child2") CONFIG.remove_bs(bspath2) self.bs2 = utp.BlockStore.create(CONFIG.BSTYPE, "child2", CONFIG.BSSIZE, CONFIG.BSARGS(bspath2)) # Third child. bspath3 = "vbs_head_01_c3" CONFIG.unmap_bs("child3") CONFIG.remove_bs(bspath3) self.bs3 = utp.BlockStore.create(CONFIG.BSTYPE, "child3", CONFIG.BSSIZE, CONFIG.BSARGS(bspath3)) # Open the virtual block store. CONFIG.unmap_bs("rootbs") self.vbs = utp.BlockStore.open("VBS", "rootbs", ("child1", "child2", "child3")) # NOTE - We used to generate NotFound on empty BS, but this # was changed to return an empty set instead. See comment # in LameHeadNodeGraph::head_furthest_async for more info. # # print "Furthest should generate NotFound on empty BS." # seed = (buffer(""), buffer("")) # py.test.raises(utp.NotFoundError, self.vbs.bs_head_furthest, seed) # # print "Furthest should generate NotFound on empty BS, even w/ fsid" # seed = (buffer("fsid"), buffer("")) # py.test.raises(utp.NotFoundError, self.vbs.bs_head_furthest, seed) print "Furthest should generate empty on empty BS." seed = (buffer(""), buffer("")) shes = self.vbs.bs_head_furthest(seed) assert lenhack(shes) == 0 print "Furthest should generate empty on empty BS, even w/ fsid" seed = (buffer("fsid"), buffer("")) shes = self.vbs.bs_head_furthest(seed) assert lenhack(shes) == 0 print "Follow should generate NotFound on empty BS." seed = (buffer(""), buffer("")) py.test.raises(utp.NotFoundError, self.vbs.bs_head_follow, seed) print "Follow should generate NotFound on empty BS, even w/ fsid" seed = (buffer("fsid"), buffer("")) py.test.raises(utp.NotFoundError, self.vbs.bs_head_follow, seed) self.vbs.bs_sync() print "Close for good." self.vbs.bs_close() self.vbs = None self.bs3.bs_close() self.bs3 = None self.bs2.bs_close() self.bs2 = None self.bs1.bs_close() self.bs1 = None CONFIG.remove_bs(bspath3) CONFIG.remove_bs(bspath2) CONFIG.remove_bs(bspath1) print "test_on_empty finished"
def test_on_independent(self): print "test_on_independent starting" # First child. bspath1 = "vbs_head_01_c1" CONFIG.unmap_bs("child1") CONFIG.remove_bs(bspath1) self.bs1 = utp.BlockStore.create(CONFIG.BSTYPE, "child1", CONFIG.BSSIZE, CONFIG.BSARGS(bspath1)) # Insert a node into this child only node1 = utp.SignedHeadEdge(("fsid", "node1", 0, time.time() * 1e6, 0, 0)) self.bs1.bs_head_insert(node1) # Second child. bspath2 = "vbs_head_01_c2" CONFIG.unmap_bs("child2") CONFIG.remove_bs(bspath2) self.bs2 = utp.BlockStore.create(CONFIG.BSTYPE, "child2", CONFIG.BSSIZE, CONFIG.BSARGS(bspath2)) # Insert a node into this child only node2 = utp.SignedHeadEdge(("fsid", "node2", 0, time.time() * 1e6, 0, 0)) self.bs2.bs_head_insert(node2) # Third child. bspath3 = "vbs_head_01_c3" CONFIG.unmap_bs("child3") CONFIG.remove_bs(bspath3) self.bs3 = utp.BlockStore.create(CONFIG.BSTYPE, "child3", CONFIG.BSSIZE, CONFIG.BSARGS(bspath3)) # Insert a node into this child only node3 = utp.SignedHeadEdge(("fsid", "node3", 0, time.time() * 1e6, 0, 0)) self.bs3.bs_head_insert(node3) # Open the virtual block store. CONFIG.unmap_bs("rootbs") self.vbs = utp.BlockStore.open("VBS", "rootbs", ("child1", "child2", "child3")) seed0 = (buffer("fsid"), buffer("")) # Follow w/ empty should return all edges. shes = self.vbs.bs_head_follow(seed0) assert lenhack(shes) == 3 assert sorted((str(shes[0].rootref), str(shes[1].rootref), str(shes[2].rootref))) == ["node1", "node2", "node3"] # Further w/ empty should return all nodes. shes = self.vbs.bs_head_furthest(seed0) assert lenhack(shes) == 3 assert sorted(shes) == [ (buffer("fsid"), buffer("node1")), (buffer("fsid"), buffer("node2")), (buffer("fsid"), buffer("node3")), ] self.vbs.bs_sync() # Close for good. self.vbs.bs_close() self.vbs = None self.bs3.bs_close() self.bs3 = None self.bs2.bs_close() self.bs2 = None self.bs1.bs_close() self.bs1 = None CONFIG.remove_bs(bspath3) CONFIG.remove_bs(bspath2) CONFIG.remove_bs(bspath1) print "test_on_independent finished"
def test_on_single(self): print "test_on_single starting" # First child. bspath1 = "vbs_head_01_c1" CONFIG.unmap_bs("child1") CONFIG.remove_bs(bspath1) self.bs1 = utp.BlockStore.create(CONFIG.BSTYPE, "child1", CONFIG.BSSIZE, CONFIG.BSARGS(bspath1)) # Second child. bspath2 = "vbs_head_01_c2" CONFIG.unmap_bs("child2") CONFIG.remove_bs(bspath2) self.bs2 = utp.BlockStore.create(CONFIG.BSTYPE, "child2", CONFIG.BSSIZE, CONFIG.BSARGS(bspath2)) # Third child. bspath3 = "vbs_head_01_c3" CONFIG.unmap_bs("child3") CONFIG.remove_bs(bspath3) self.bs3 = utp.BlockStore.create(CONFIG.BSTYPE, "child3", CONFIG.BSSIZE, CONFIG.BSARGS(bspath3)) # Open the virtual block store. CONFIG.unmap_bs("rootbs") self.vbs = utp.BlockStore.open("VBS", "rootbs", ("child1", "child2", "child3")) # Insert a single SHN. node = utp.SignedHeadEdge(("fsid", "rootref", 0, time.time() * 1e6, 0, 0)) self.vbs.bs_head_insert(node) # Follow should return the node we inserted. seed = (buffer("fsid"), buffer("")) shes = self.vbs.bs_head_follow(seed) assert lenhack(shes) == 1 assert str(shes[0].rootref) == "rootref" # Furthest should return the node we inserted. seed = (buffer("fsid"), buffer("")) shes = self.vbs.bs_head_furthest(seed) assert lenhack(shes) == 1 assert shes[0] == (buffer("fsid"), buffer("rootref")) self.vbs.bs_sync() # Close for good. self.vbs.bs_close() self.vbs = None self.bs3.bs_close() self.bs3 = None self.bs2.bs_close() self.bs2 = None self.bs1.bs_close() self.bs1 = None CONFIG.remove_bs(bspath3) CONFIG.remove_bs(bspath2) CONFIG.remove_bs(bspath1) print "test_on_single finished"
def test_two_nodes(self): self.bs = utp.BlockStore.create(CONFIG.BSTYPE, "rootbs", CONFIG.BSSIZE, CONFIG.BSARGS(self.bspath)) # Insert the first SHN. node1 = utp.SignedHeadEdge(("fsid", "node1", 0, time.time() * 1e6, 0, 0)) self.bs.bs_head_insert(node1) # Insert the second SHN. node2 = utp.SignedHeadEdge(("fsid", "node2", "node1", time.time() * 1e6, 0, 0)) self.bs.bs_head_insert(node2) # The third SHN is a branch. node3 = utp.SignedHeadEdge(("fsid", "node3", "node1", time.time() * 1e6, 0, 0)) self.bs.bs_head_insert(node3) # Furthest w/ empty should return the two branch heads. seed0 = (buffer("fsid"), buffer("")) shes = self.bs.bs_head_furthest(seed0) assert lenhack(shes) == 2 assert sorted(shes) == [ (buffer("fsid"), buffer("node2")), (buffer("fsid"), buffer("node3")), ] # Furthest w/ first should return the two branch heads. seed1 = (buffer("fsid"), buffer("node1")) shes = self.bs.bs_head_furthest(seed1) assert lenhack(shes) == 2 assert sorted(shes) == [ (buffer("fsid"), buffer("node2")), (buffer("fsid"), buffer("node3")), ] # Furthest w/ one branch should return that branch. seed2 = (buffer("fsid"), buffer("node2")) shes = self.bs.bs_head_furthest(seed2) assert lenhack(shes) == 1 assert shes == [ (buffer("fsid"), buffer("node2")), ] # Follow w/ empty should return all nodes. shes = self.bs.bs_head_follow(seed0) assert lenhack(shes) == 3 assert sorted((str(shes[0].rootref), str(shes[1].rootref), str(shes[2].rootref))) == ["node1", "node2", "node3"] # Follow w/ first should return all nodes except the starting. shes = self.bs.bs_head_follow(seed1) assert lenhack(shes) == 2 assert sorted((str(shes[0].rootref), str(shes[1].rootref))) == ["node2", "node3"] # Follow w/ branch head should return nothing. seed3 = (buffer("fsid"), buffer("node3")) shes = self.bs.bs_head_follow(seed3) assert lenhack(shes) == 0 # Reopen the blockstore. self.bs.bs_close() self.bs = utp.BlockStore.open(CONFIG.BSTYPE, "rootbs", CONFIG.BSARGS(self.bspath)) # Furthest w/ empty should return the two branch heads. seed0 = (buffer("fsid"), buffer("")) shes = self.bs.bs_head_furthest(seed0) assert lenhack(shes) == 2 assert sorted(shes) == [ (buffer("fsid"), buffer("node2")), (buffer("fsid"), buffer("node3")), ] # Furthest w/ first should return the two branch heads. seed1 = (buffer("fsid"), buffer("node1")) shes = self.bs.bs_head_furthest(seed1) assert lenhack(shes) == 2 assert sorted(shes) == [ (buffer("fsid"), buffer("node2")), (buffer("fsid"), buffer("node3")), ] # Furthest w/ one branch should return that branch. seed2 = (buffer("fsid"), buffer("node2")) shes = self.bs.bs_head_furthest(seed2) assert lenhack(shes) == 1 assert shes == [(buffer("fsid"), buffer("node2")), ] # Follow w/ empty should return all nodes. shes = self.bs.bs_head_follow(seed0) assert lenhack(shes) == 3 assert sorted((str(shes[0].rootref), str(shes[1].rootref), str(shes[2].rootref))) == ["node1", "node2", "node3"] # Follow w/ first should return all nodes except the starting. shes = self.bs.bs_head_follow(seed1) assert lenhack(shes) == 2 assert sorted((str(shes[0].rootref), str(shes[1].rootref))) == ["node2", "node3"] # Follow w/ branch head should return nothing. seed3 = (buffer("fsid"), buffer("node3")) shes = self.bs.bs_head_follow(seed3) assert lenhack(shes) == 0 # Close the blockstore. self.bs.bs_close() CONFIG.remove_bs(self.bspath)
def test_furthest_on_empty(self): CONFIG.unmap_bs("rootbs") CONFIG.remove_bs(self.bspath) self.bs = utp.BlockStore.create(CONFIG.BSTYPE, "rootbs", CONFIG.BSSIZE, CONFIG.BSARGS(self.bspath)) # NOTE - We used to generate NotFound on empty BS, but this # was changed to return an empty set instead. See comment # in LameHeadNodeGraph::head_furthest_async for more info. # # # Furthest should generate NotFound on empty BS. # seed = (buffer(""), buffer("")) # py.test.raises(utp.NotFoundError, self.bs.bs_head_furthest, seed) # # # Furthest should generate NotFound on empty BS, even w/ fsid # seed = (buffer("fsid"), buffer("")) # py.test.raises(utp.NotFoundError, self.bs.bs_head_furthest, seed) # Furthest should generate empty set on empty BS. seed = (buffer(""), buffer("")) shes = self.bs.bs_head_furthest(seed) assert lenhack(shes) == 0 # Furthest should generate empty set on empty BS, even w/ fsid seed = (buffer("fsid"), buffer("")) shes = self.bs.bs_head_furthest(seed) assert lenhack(shes) == 0 # Reopen the blockstore. self.bs.bs_close() self.bs = utp.BlockStore.open(CONFIG.BSTYPE, "rootbs", CONFIG.BSARGS(self.bspath)) # NOTE - We used to generate NotFound on empty BS, but this # was changed to return an empty set instead. See comment # in LameHeadNodeGraph::head_furthest_async for more info. # # # Furthest should generate NotFound on empty BS. # seed = (buffer(""), buffer("")) # py.test.raises(utp.NotFoundError, self.bs.bs_head_furthest, seed) # # # Furthest should generate NotFound on empty BS, even w/ fsid # seed = (buffer("fsid"), buffer("")) # py.test.raises(utp.NotFoundError, self.bs.bs_head_furthest, seed) # Furthest should generate NotFound on empty BS. seed = (buffer(""), buffer("")) shes = self.bs.bs_head_furthest(seed) assert lenhack(shes) == 0 # Furthest should generate NotFound on empty BS, even w/ fsid seed = (buffer("fsid"), buffer("")) shes = self.bs.bs_head_furthest(seed) assert lenhack(shes) == 0 # Close the blockstore. self.bs.bs_close() CONFIG.remove_bs(self.bspath)
def test_on_delta(self): # First child. bspath1 = "vbs_head_02_c1" CONFIG.unmap_bs("child1") CONFIG.remove_bs(bspath1) self.bs1 = utp.BlockStore.create(CONFIG.BSTYPE, "child1", CONFIG.BSSIZE, CONFIG.BSARGS(bspath1)) # Second child. bspath2 = "vbs_head_02_c2" CONFIG.unmap_bs("child2") CONFIG.remove_bs(bspath2) self.bs2 = utp.BlockStore.create(CONFIG.BSTYPE, "child2", CONFIG.BSSIZE, CONFIG.BSARGS(bspath2)) # Third child. bspath3 = "vbs_head_02_c3" CONFIG.unmap_bs("child3") CONFIG.remove_bs(bspath3) self.bs3 = utp.BlockStore.create(CONFIG.BSTYPE, "child3", CONFIG.BSSIZE, CONFIG.BSARGS(bspath3)) # Open the virtual block store. CONFIG.unmap_bs("rootbs") self.vbs = utp.BlockStore.open("VBS", "rootbs", ("child1", "child2", "child3")) # Insert a single SHN. node1 = utp.SignedHeadEdge(("fsid", "node1", 0, time.time() * 1e6, 0, 0)) self.vbs.bs_head_insert(node1) # Insert a child SHN. node2 = utp.SignedHeadEdge(("fsid", "node2", "node1", time.time() * 1e6, 0, 0)) self.vbs.bs_head_insert(node2) # Insert a new node into one child only. node3 = utp.SignedHeadEdge(("fsid", "node3", "node2", time.time() * 1e6, 0, 0)) self.bs3.bs_head_insert(node3) seed0 = (buffer("fsid"), buffer("")) # Follow w/ empty should return all nodes. shes = self.vbs.bs_head_follow(seed0) assert lenhack(shes) == 3 assert sorted((str(shes[0].rootref), str(shes[1].rootref), str(shes[2].rootref))) == ["node1", "node2", "node3"] # Further w/ empty should return the top node. shes = self.vbs.bs_head_furthest(seed0) assert lenhack(shes) == 1 assert shes[0] == (buffer("fsid"), buffer("node3")) # Close and reopen without the special child. self.vbs.bs_close() self.bs3.bs_close() self.bs2.bs_close() self.bs1.bs_close() self.bs1 = utp.BlockStore.open(CONFIG.BSTYPE, "child1", CONFIG.BSARGS(bspath1)) self.bs2 = utp.BlockStore.open(CONFIG.BSTYPE, "child2", CONFIG.BSARGS(bspath2)) self.vbs = utp.BlockStore.open("VBS", "rootbs", ("child1", "child2")) # Follow w/ empty should return all nodes. shes = self.vbs.bs_head_follow(seed0) assert lenhack(shes) == 3 assert sorted((str(shes[0].rootref), str(shes[1].rootref), str(shes[2].rootref))) == ["node1", "node2", "node3"] # Further w/ empty should return the top node. shes = self.vbs.bs_head_furthest(seed0) assert lenhack(shes) == 1 assert shes[0] == (buffer("fsid"), buffer("node3")) self.vbs.bs_sync() # Close for good. self.vbs.bs_close() self.vbs = None self.bs2.bs_close() self.bs2 = None self.bs1.bs_close() self.bs1 = None CONFIG.remove_bs(bspath3) CONFIG.remove_bs(bspath2) CONFIG.remove_bs(bspath1)
def test_two_nodes(self): self.bs = utp.BlockStore.create(CONFIG.BSTYPE, "rootbs", CONFIG.BSSIZE, CONFIG.BSARGS(self.bspath)) # Insert the first SHN. node1 = utp.SignedHeadEdge(("fsid", "node1", 0, time.time() * 1e6, 0, 0)) self.bs.bs_head_insert(node1) # Insert the second SHN. node2a = utp.SignedHeadEdge(("fsid", "node2a", "node1", time.time() * 1e6, 0, 0)) self.bs.bs_head_insert(node2a) # Another node is a branch. node2b = utp.SignedHeadEdge(("fsid", "node2b", "node1", time.time() * 1e6, 0, 0)) self.bs.bs_head_insert(node2b) # A merge node. node3a = utp.SignedHeadEdge(("fsid", "node3", "node2a", time.time() * 1e6, 0, 0)) self.bs.bs_head_insert(node3a) # Another merge node. node3b = utp.SignedHeadEdge(("fsid", "node3", "node2b", time.time() * 1e6, 0, 0)) self.bs.bs_head_insert(node3b) # Furthest w/ empty should return the the merge head. seed0 = (buffer("fsid"), buffer("")) shes = self.bs.bs_head_furthest(seed0) assert lenhack(shes) == 1 assert shes[0] == (buffer("fsid"), buffer("node3")) # Furthest w/ first should return the merge head. seed1 = (buffer("fsid"), buffer("node1")) shes = self.bs.bs_head_furthest(seed1) assert lenhack(shes) == 1 assert shes[0] == (buffer("fsid"), buffer("node3")) # Furthest w/ one branch should return the merge head. seed2a = (buffer("fsid"), buffer("node2a")) shes = self.bs.bs_head_furthest(seed2a) assert lenhack(shes) == 1 assert shes[0] == (buffer("fsid"), buffer("node3")) # Follow w/ empty should return all nodes. shes = self.bs.bs_head_follow(seed0) assert lenhack(shes) == 5 assert sorted( ( str(shes[0].rootref), str(shes[1].rootref), str(shes[2].rootref), str(shes[3].rootref), str(shes[4].rootref), ) ) == ["node1", "node2a", "node2b", "node3", "node3"] # Follow w/ first should return all nodes except the starting. shes = self.bs.bs_head_follow(seed1) assert lenhack(shes) == 4 assert sorted((str(shes[0].rootref), str(shes[1].rootref), str(shes[2].rootref), str(shes[3].rootref))) == [ "node2a", "node2b", "node3", "node3", ] # Follow w/ branch should return that branch only. seed2b = (buffer("fsid"), buffer("node2b")) shes = self.bs.bs_head_follow(seed2b) assert lenhack(shes) == 1 assert str(shes[0].rootref) == "node3" assert str(shes[0].prevref) == "node2b" # Reopen the blockstore. self.bs.bs_close() self.bs = utp.BlockStore.open(CONFIG.BSTYPE, "rootbs", CONFIG.BSARGS(self.bspath)) # Furthest w/ empty should return the the merge head. shes = self.bs.bs_head_furthest(seed0) assert lenhack(shes) == 1 assert shes[0] == (buffer("fsid"), buffer("node3")) # Furthest w/ first should return the merge head. shes = self.bs.bs_head_furthest(seed1) assert lenhack(shes) == 1 assert shes[0] == (buffer("fsid"), buffer("node3")) # Furthest w/ one branch should return the merge head. shes = self.bs.bs_head_furthest(seed2b) assert lenhack(shes) == 1 assert shes[0] == (buffer("fsid"), buffer("node3")) # Follow w/ empty should return all nodes. shes = self.bs.bs_head_follow(seed0) assert lenhack(shes) == 5 assert sorted( ( str(shes[0].rootref), str(shes[1].rootref), str(shes[2].rootref), str(shes[3].rootref), str(shes[4].rootref), ) ) == ["node1", "node2a", "node2b", "node3", "node3"] # Follow w/ first should return all nodes except the starting. shes = self.bs.bs_head_follow(seed1) assert lenhack(shes) == 4 assert sorted((str(shes[0].rootref), str(shes[1].rootref), str(shes[2].rootref), str(shes[3].rootref))) == [ "node2a", "node2b", "node3", "node3", ] # Follow w/ branch should return that branch only. shes = self.bs.bs_head_follow(seed2a) assert lenhack(shes) == 1 assert str(shes[0].rootref) == "node3" assert str(shes[0].prevref) == "node2a" # Close the blockstore. self.bs.bs_close() CONFIG.remove_bs(self.bspath)