Exemplo n.º 1
0
    def test_add_stream_to_duplicate_consumer(self):

        op = self.upr_client.open_consumer("mystream")
        response = op.next_response()
        assert response['status'] == SUCCESS

        upr_client2 = UprClient(self.host, self.port)
        op = upr_client2.open_consumer("mystream")
        response = op.next_response()
        assert response['status'] == SUCCESS

        op = self.upr_client.add_stream(0, 0)
        response = op.next_response()
        assert response['status'] == ERR_ECLIENT

        op = upr_client2.add_stream(0, 0)
        response = op.next_response()
        assert response['status'] == SUCCESS
Exemplo n.º 2
0
def add_stream_demo():
    upr_client = UprClient('127.0.0.1', 12000)
    mcd_client = McdClient('127.0.0.1', 12000)
    op = upr_client.open_consumer("mystream")
    print 'Sending open connection (consumer)'
    print op
    response = op.next_response()
    print 'Response: %s\n' % response
    assert response['status'] == SUCCESS

    op = upr_client.add_stream(0, 0)
    print 'Sending add stream request'
    print op
    response = op.next_response()
    assert response['status'] == SUCCESS
    print 'Got add stream response'
    print response

    upr_client.shutdown()
    mcd_client.shutdown()
Exemplo n.º 3
0
def add_stream_demo():
    upr_client = UprClient('127.0.0.1', 12000)
    mcd_client = McdClient('127.0.0.1', 12000)
    op = upr_client.open_consumer("mystream")
    print 'Sending open connection (consumer)'
    print op
    response = op.next_response()
    print 'Response: %s\n' % response
    assert response['status'] == SUCCESS

    op = upr_client.add_stream(0, 0)
    print 'Sending add stream request'
    print op
    response = op.next_response()
    assert response['status'] == SUCCESS
    print 'Got add stream response'
    print response

    upr_client.shutdown()
    mcd_client.shutdown()
Exemplo n.º 4
0
def two_way_demo():
    consumer = UprClient('127.0.0.1', 5000)
    producer = UprClient('127.0.0.1', 5001)
    consumer.set_proxy(producer)
    producer.set_proxy(consumer)

    mcd_consumer = McdClient('127.0.0.1', 5000)
    mcd_producer = McdClient('127.0.0.1', 5001)

    response = get_resp(consumer.open_consumer("mystream"), 'Sending open connection (consumer)')
    assert response['status'] == SUCCESS

    response = get_resp(producer.open_producer("mystream"), 'Sending open connection (producer)')
    assert response['status'] == SUCCESS

    response = get_resp(consumer.add_stream(0, 0), 'Sending add stream request for vbucket 0')
    assert response['status'] == SUCCESS

    op = mcd_consumer.stats('upr')
    response = op.next_response()
    print response['value']
    assert response['value']['ep_upr_count'] == '1'

    op = mcd_producer.stats('upr')
    response = op.next_response()
    print response['value']
    assert response['value']['ep_upr_count'] == '1'

    get_resp(mcd_producer.set("key", "blah", 0, 0, 0), 'Create mutation on producer')

    time.sleep(3)
    get_resp(mcd_producer.delete("key", 0), 'Create mutation on producer')

    time.sleep(10)

    consumer.shutdown()
    producer.shutdown()
    mcd_consumer.shutdown()
    mcd_producer.shutdown()
Exemplo n.º 5
0
Arquivo: unit.py Projeto: vmx/pyupr
class UprTestCase(ParametrizedTestCase):
    def setUp(self):
        self.upr_client = UprClient(self.host, self.port)
        self.mcd_client = McdClient(self.host, self.port)
        if self.backend == RemoteServer.MCD:
            resp = self.mcd_client.flush().next_response()
            assert resp["status"] == SUCCESS, "Flush all is not enabled"

    def tearDown(self):
        self.upr_client.shutdown()
        self.mcd_client.shutdown()

    """Basic upr open consumer connection test

    Verifies that when the open upr consumer command is used there is a
    connection instance that is created on the server and that when the
    tcp connection is closed the connection is remove from the server"""

    def test_open_consumer_connection_command(self):
        op = self.upr_client.open_consumer("mystream")
        response = op.next_response()
        assert response["status"] == SUCCESS

        op = self.mcd_client.stats("tap")
        response = op.next_response()
        assert response["value"]["mystream:type"] == "consumer"

        self.upr_client.shutdown()
        op = self.mcd_client.stats("tap")
        response = op.next_response()
        assert "mystream:type" not in response["value"]

    """Basic upr open producer connection test

    Verifies that when the open upr producer command is used there is a
    connection instance that is created on the server and that when the
    tcp connection is closed the connection is remove from the server"""

    def test_open_producer_connection_command(self):
        op = self.upr_client.open_producer("mystream")
        response = op.next_response()
        assert response["status"] == SUCCESS

        op = self.mcd_client.stats("tap")
        response = op.next_response()
        assert response["value"]["mystream:type"] == "producer"

        self.upr_client.shutdown()
        op = self.mcd_client.stats("tap")
        response = op.next_response()
        assert "mystream:type" not in response["value"]

    """Basic add stream test

    This test verifies a simple add stream command. It expects that a stream
    request message will be sent to the producer before a response for the
    add stream command is returned."""

    def test_add_stream_command(self):
        op = self.upr_client.open_consumer("mystream")
        response = op.next_response()
        assert response["status"] == SUCCESS

        op = self.upr_client.add_stream(0, 0)
        response = op.next_response()
        assert response["status"] == SUCCESS

    """Add stream command with no consumer vbucket

    Attempts to add a stream when no vbucket exists on the consumer. The
    client shoudl expect a not my vbucket response immediately"""

    def test_add_stream_not_my_vbucket(self):
        op = self.upr_client.open_consumer("mystream")
        response = op.next_response()
        assert response["status"] == SUCCESS

        op = self.upr_client.add_stream(1025, 0)
        response = op.next_response()
        assert response["status"] == ERR_NOT_MY_VBUCKET

    """Add stream when stream exists

    Creates a stream and then attempts to create another stream for the
    same vbucket. Expects to fail with an exists error."""

    def test_add_stream_exists(self):
        op = self.upr_client.open_consumer("mystream")
        response = op.next_response()
        assert response["status"] == SUCCESS

        op = self.upr_client.add_stream(0, 0)
        response = op.next_response()
        assert response["status"] == SUCCESS

        op = self.upr_client.add_stream(0, 0)
        response = op.next_response()
        assert response["status"] == ERR_KEY_EEXISTS

    def test_close_stream_command(self):
        op = self.upr_client.close_stream(0)
        response = op.next_response()
        assert response["status"] == ERR_NOT_SUPPORTED

    def test_get_failover_log_command(self):
        op = self.upr_client.get_failover_log(0)
        response = op.next_response()
        assert response["status"] == ERR_NOT_SUPPORTED

    """Basic upr stream request

    Opens a producer connection and sends a stream request command for
    vbucket 0. Since no items exist in the server we should accept the
    stream request and then send back a stream end message."""

    def test_stream_request_command(self):
        op = self.upr_client.open_producer("mystream")
        response = op.next_response()
        assert response["status"] == SUCCESS

        op = self.upr_client.stream_req(0, 0, 0, 0, 0, 0)
        while op.has_response():
            response = op.next_response()
            assert response["status"] == SUCCESS

    @skipUnlessMcd
    def test_stream_request_with_ops(self):
        for i in range(10):
            op = self.mcd_client.set("key" + str(i), "value", 0, 0, 0)
            resp = op.next_response()
            assert resp["status"] == SUCCESS

        op = self.mcd_client.stats("vbucket-seqno")
        resp = op.next_response()
        assert resp["status"] == SUCCESS
        end_seqno = int(resp["value"]["vb_0"])

        op = self.upr_client.open_producer("mystream")
        response = op.next_response()
        assert response["status"] == SUCCESS

        op = self.upr_client.stream_req(0, 0, 0, end_seqno, 0, 0)
        while op.has_response():
            response = op.next_response()
            assert response["status"] == SUCCESS
            print response

    @skipUnlessMcd
    def test_stream_request_with_deletes(self):
        for i in range(10):
            op = self.mcd_client.set("key" + str(i), "value", 0, 0, 0)
            resp = op.next_response()
            assert resp["status"] == SUCCESS

        op = self.mcd_client.stats("vbucket-seqno")
        resp = op.next_response()
        assert resp["status"] == SUCCESS
        end_seqno = int(resp["value"]["vb_0"])

        op = self.upr_client.open_producer("mystream")
        response = op.next_response()
        assert response["status"] == SUCCESS

        op = self.upr_client.stream_req(0, 0, 0, end_seqno, 0, 0)
        while op.has_response():
            response = op.next_response()
            assert response["status"] == SUCCESS
            print response