Пример #1
0
 def testWriteString_NotConnected(self):
     key = "_WriteString_NotConnected"
     conn = TransactionSingleOp()
     conn.close_connection()
     #self.assertRaises(scalaris.ConnectionError, conn.write, str(self._testTime) + key, _TEST_DATA[0])
     conn.write(str(self._testTime) + key, _TEST_DATA[0])
     conn.close_connection()
Пример #2
0
 def testReqTooLarge(self):
     conn = TransactionSingleOp()
     data = '0' * _TOO_LARGE_REQUEST_SIZE
     key = "_ReqTooLarge"
     try:
         conn.write(str(self._testTime) + key, data)
         self.fail('The write should have failed unless yaws_max_post_data was set larger than ' + str(_TOO_LARGE_REQUEST_SIZE))
     except scalaris.ConnectionError:
         pass
     
     conn.close_connection()
Пример #3
0
 def testWriteString2(self):
     key = "_WriteString2"
     conn = TransactionSingleOp()
     
     for i in xrange(len(_TEST_DATA)):
         conn.write(str(self._testTime) + key, _TEST_DATA[i])
     
     # now try to read the data:
     actual = conn.read(str(self._testTime) + key)
     self.assertEqual(actual, _TEST_DATA[len(_TEST_DATA) - 1])
     conn.close_connection()
Пример #4
0
 def testWriteList2(self):
     key = "_WriteList2"
     conn = TransactionSingleOp()
     
     mylist = []
     for i in xrange(0, len(_TEST_DATA) - 1, 2):
         mylist = [_TEST_DATA[i], _TEST_DATA[i + 1]]
         conn.write(str(self._testTime) + key, mylist)
     
     # now try to read the data:
     actual = conn.read(str(self._testTime) + key)
     self.assertEqual(actual, mylist)
     conn.close_connection()
Пример #5
0
 def testWriteList1(self):
     key = "_WriteList1_"
     conn = TransactionSingleOp()
     
     for i in xrange(0, len(_TEST_DATA) - 1, 2):
         conn.write(str(self._testTime) + key + str(i), [_TEST_DATA[i], _TEST_DATA[i + 1]])
     
     # now try to read the data:
     for i in xrange(0, len(_TEST_DATA), 2):
         actual = conn.read(str(self._testTime) + key + str(i))
         self.assertEqual(actual, [_TEST_DATA[i], _TEST_DATA[i + 1]])
     
     conn.close_connection()
Пример #6
0
    def testWriteString1(self):
        key = "_WriteString1_"
        conn = TransactionSingleOp()

        for i in xrange(len(_TEST_DATA)):
            conn.write(str(self._testTime) + key + str(i), _TEST_DATA[i])

        # now try to read the data:
        for i in xrange(len(_TEST_DATA)):
            actual = conn.read(str(self._testTime) + key + str(i))
            self.assertEqual(actual, _TEST_DATA[i])

        conn.close_connection()
Пример #7
0
    def testReqTooLarge(self):
        conn = TransactionSingleOp()
        data = '0' * _TOO_LARGE_REQUEST_SIZE
        key = "_ReqTooLarge"
        try:
            conn.write(str(self._testTime) + key, data)
            self.fail(
                'The write should have failed unless yaws_max_post_data was set larger than '
                + str(_TOO_LARGE_REQUEST_SIZE))
        except scalaris.ConnectionError:
            pass

        conn.close_connection()
Пример #8
0
    def testWriteList2(self):
        key = "_WriteList2"
        conn = TransactionSingleOp()

        mylist = []
        for i in xrange(0, len(_TEST_DATA) - 1, 2):
            mylist = [_TEST_DATA[i], _TEST_DATA[i + 1]]
            conn.write(str(self._testTime) + key, mylist)

        # now try to read the data:
        actual = conn.read(str(self._testTime) + key)
        self.assertEqual(actual, mylist)
        conn.close_connection()
Пример #9
0
    def testWriteList1(self):
        key = "_WriteList1_"
        conn = TransactionSingleOp()

        for i in xrange(0, len(_TEST_DATA) - 1, 2):
            conn.write(
                str(self._testTime) + key + str(i),
                [_TEST_DATA[i], _TEST_DATA[i + 1]])

        # now try to read the data:
        for i in xrange(0, len(_TEST_DATA), 2):
            actual = conn.read(str(self._testTime) + key + str(i))
            self.assertEqual(actual, [_TEST_DATA[i], _TEST_DATA[i + 1]])

        conn.close_connection()
Пример #10
0
 def testTestAndSetList1(self):
     key = "_TestAndSetList1"
     conn = TransactionSingleOp()
     
     # first write all values:
     for i in xrange(0, len(_TEST_DATA) - 1, 2):
         conn.write(str(self._testTime) + key + str(i), [_TEST_DATA[i], _TEST_DATA[i + 1]])
     
     # now try to overwrite them using test_and_set:
     for i in xrange(0, len(_TEST_DATA) - 1, 2):
         conn.test_and_set(str(self._testTime) + key + str(i), [_TEST_DATA[i], _TEST_DATA[i + 1]], [_TEST_DATA[i + 1], _TEST_DATA[i]])
     
     # now try to read the data:
     for i in xrange(0, len(_TEST_DATA) - 1, 2):
         actual = conn.read(str(self._testTime) + key + str(i))
         self.assertEqual(actual, [_TEST_DATA[i + 1], _TEST_DATA[i]])
     
     conn.close_connection()
Пример #11
0
    def testTestAndSetString1(self):
        key = "_TestAndSetString1"
        conn = TransactionSingleOp()

        # first write all values:
        for i in xrange(0, len(_TEST_DATA) - 1, 2):
            conn.write(str(self._testTime) + key + str(i), _TEST_DATA[i])

        # now try to overwrite them using test_and_set:
        for i in xrange(0, len(_TEST_DATA) - 1, 2):
            conn.test_and_set(
                str(self._testTime) + key + str(i), _TEST_DATA[i],
                _TEST_DATA[i + 1])

        # now try to read the data:
        for i in xrange(0, len(_TEST_DATA), 2):
            actual = conn.read(str(self._testTime) + key + str(i))
            self.assertEqual(actual, _TEST_DATA[i + 1])

        conn.close_connection()
Пример #12
0
 def testTestAndSetList2(self):
     key = "_TestAndSetList2"
     conn = TransactionSingleOp()
     
     # first write all values:
     for i in xrange(0, len(_TEST_DATA) - 1, 2):
         conn.write(str(self._testTime) + key + str(i), [_TEST_DATA[i], _TEST_DATA[i + 1]])
     
     # now try to overwrite them using test_and_set:
     for i in xrange(0, len(_TEST_DATA) - 1, 2):
         try:
             conn.test_and_set(str(self._testTime) + key + str(i), "fail", 1)
             self.fail('expected a KeyChangedError')
         except scalaris.KeyChangedError as exception:
             self.assertEqual(exception.old_value, [_TEST_DATA[i], _TEST_DATA[i + 1]])
     
     # now try to read the data:
     for i in xrange(0, len(_TEST_DATA) - 1, 2):
         actual = conn.read(str(self._testTime) + key + str(i))
         self.assertEqual(actual, [_TEST_DATA[i], _TEST_DATA[i + 1]])
     
     conn.close_connection()
Пример #13
0
    def testTestAndSetString2(self):
        key = "_TestAndSetString2"
        conn = TransactionSingleOp()

        # first write all values:
        for i in xrange(0, len(_TEST_DATA) - 1, 2):
            conn.write(str(self._testTime) + key + str(i), _TEST_DATA[i])

        # now try to overwrite them using test_and_set:
        for i in xrange(0, len(_TEST_DATA) - 1, 2):
            try:
                conn.test_and_set(
                    str(self._testTime) + key + str(i), _TEST_DATA[i + 1],
                    "fail")
                self.fail('expected a KeyChangedError')
            except scalaris.KeyChangedError as exception:
                self.assertEqual(exception.old_value, _TEST_DATA[i])

        # now try to read the data:
        for i in xrange(0, len(_TEST_DATA), 2):
            actual = conn.read(str(self._testTime) + key + str(i))
            self.assertEqual(actual, _TEST_DATA[i])

        conn.close_connection()
Пример #14
0
         sys.exit(1)
     except TimeoutError as instance:
         print 'read(' + key + ') failed with timeout'
         sys.exit(1)
     except NotFoundError as instance:
         print 'read(' + key + ') failed with not_found'
         sys.exit(1)
     except UnknownError as instance:
         print 'read(' + key + ') failed with unknown: ' + str(instance)
         sys.exit(1)
 elif (len(sys.argv) == 4 and sys.argv[1] in ["--write", "-w"]):
     sc = TransactionSingleOp()
     key = sys.argv[2]
     value = sys.argv[3]
     try:
         sc.write(key, value)
         print 'write(' + key + ', ' + value + '): ok'
     except ConnectionError as instance:
         print 'write(' + key + ', ' + value + ') failed with connection error'
         sys.exit(1)
     except TimeoutError as instance:
         print 'write(' + key + ', ' + value + ') failed with timeout'
         sys.exit(1)
     except AbortError as instance:
         print 'write(' + key + ', ' + value + ') failed with abort'
         sys.exit(1)
     except UnknownError as instance:
         print 'write(' + key + ', ' + value + ') failed with unknown: ' + str(instance)
         sys.exit(1)
 elif (len(sys.argv) == 5 and sys.argv[1] == "--test-and-set"):
     sc = TransactionSingleOp()
Пример #15
0
         sys.exit(1)
     except TimeoutError as instance:
         print 'read(' + key + ') failed with timeout'
         sys.exit(1)
     except NotFoundError as instance:
         print 'read(' + key + ') failed with not_found'
         sys.exit(1)
     except UnknownError as instance:
         print 'read(' + key + ') failed with unknown: ' + str(instance)
         sys.exit(1)
 elif (len(sys.argv) == 4 and sys.argv[1] in ["--write", "-w"]):
     sc = TransactionSingleOp()
     key = sys.argv[2]
     value = sys.argv[3]
     try:
         sc.write(key, value)
         print 'write(' + key + ', ' + value + '): ok'
     except ConnectionError as instance:
         print 'write(' + key + ', ' + value + ') failed with connection error'
         sys.exit(1)
     except TimeoutError as instance:
         print 'write(' + key + ', ' + value + ') failed with timeout'
         sys.exit(1)
     except AbortError as instance:
         print 'write(' + key + ', ' + value + ') failed with abort'
         sys.exit(1)
     except UnknownError as instance:
         print 'write(' + key + ', ' + value + ') failed with unknown: ' + str(
             instance)
         sys.exit(1)
 elif (len(sys.argv) == 5 and sys.argv[1] == "--test-and-set"):