예제 #1
0
def test_ReplList():
	l = ReplList()
	l.reset([1, 2, 3], _doApply=True)
	assert l.rawData() == [1, 2, 3]
	l.set(1, 10, _doApply=True)
	assert l.rawData() == [1, 10, 3]
	l.append(42, _doApply=True)
	assert l.rawData() == [1, 10, 3, 42]
	l.extend([5, 6], _doApply=True)
	assert l.rawData() == [1, 10, 3, 42, 5, 6]
	l.insert(2, 66, _doApply=True)
	assert l.rawData() == [1, 10, 66, 3, 42, 5, 6]
	l.remove(66, _doApply=True)
	assert l.rawData() == [1, 10, 3, 42, 5, 6]
	l.pop(1, _doApply=True)
	assert l.rawData() == [1, 3, 42, 5, 6]
	l.sort(reverse=True, _doApply=True)
	assert l.rawData() == [42, 6, 5, 3, 1]
	assert l.index(6) == 1
	assert l.count(42) == 1
	assert l.get(2) == 5
	assert l[4] == 1
	assert len(l) == 5
	l.__setitem__(0, 43, _doApply=True)
	assert l[0] == 43
예제 #2
0

if __name__ == '__main__':
    if len(sys.argv) < 3:
        print('Usage: %s self_port partner1_port partner2_port ...' %
              sys.argv[0])
        sys.exit(-1)

    port = int(sys.argv[1])
    partners = ['localhost:%d' % int(p) for p in sys.argv[2:]]
    q = ReplList()
    sync = SyncObj('localhost:%d' % port, partners, consumers=[q])
    # for item in range(5):
    #     q.append(item)
    while True:
        q.insert(0, 10)
        print q.rawData()
        time.sleep(10)

    # q.remove(4)
    # print q.rawData()

    # q = FTQueue('localhost:{}'.format(port),partners)
    # num_clients = 3
    # label = 0
    # # while num_clients > 0:
    # #     ID = q.qCreate(label)
    # #     q.qPush(ID,1)
    # #     q.qPush(ID,2)
    # #     q.qPush(ID,3)
    # #listOfQObjects = []