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()
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()
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()
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()
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() key = sys.argv[2] old_value = sys.argv[3] new_value = sys.argv[4] try: sc.test_and_set(key, old_value, new_value) print 'test_and_set(' + key + ', ' + old_value + ', ' + new_value + '): ok' except ConnectionError as instance: print 'test_and_set(' + key + ', ' + old_value + ', ' + new_value + ') failed with connection error' sys.exit(1) except TimeoutError as instance: print 'test_and_set(' + key + ', ' + old_value + ', ' + new_value + ') failed with timeout' sys.exit(1) except AbortError as instance: print 'test_and_set(' + key + ', ' + old_value + ', ' + new_value + ') failed with abort' sys.exit(1) except KeyChangedError as instance: print 'test_and_set(' + key + ', ' + old_value + ', ' + new_value + ') failed with key_change (current old value: ' + instance.old_value + ')' sys.exit(1) except UnknownError as instance: print 'test_and_set(' + key + ', ' + old_value + ', ' + new_value + ') failed with unknown: ' + str(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() key = sys.argv[2] old_value = sys.argv[3] new_value = sys.argv[4] try: sc.test_and_set(key, old_value, new_value) print 'test_and_set(' + key + ', ' + old_value + ', ' + new_value + '): ok' except ConnectionError as instance: print 'test_and_set(' + key + ', ' + old_value + ', ' + new_value + ') failed with connection error' sys.exit(1) except TimeoutError as instance: print 'test_and_set(' + key + ', ' + old_value + ', ' + new_value + ') failed with timeout' sys.exit(1) except AbortError as instance: print 'test_and_set(' + key + ', ' + old_value + ', ' + new_value + ') failed with abort' sys.exit(1) except KeyChangedError as instance: print 'test_and_set(' + key + ', ' + old_value + ', ' + new_value + ') failed with key_change (current old value: ' + instance.old_value + ')' sys.exit(1) except UnknownError as instance: print 'test_and_set(' + key + ', ' + old_value + ', ' + new_value + ') failed with unknown: ' + str(