def testRead_NotConnected(self): key = "_Read_NotConnected" t = Transaction() t.close_connection() #self.assertRaises(scalaris.ConnectionError, t.read, str(self._testTime) + key) self.assertRaises(scalaris.NotFoundError, t.read, str(self._testTime) + key) t.close_connection()
def testReqTooLarge(self): conn = Transaction() 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()
def testWriteString_NotConnected(self): key = "_WriteString_NotConnected" t = Transaction() t.close_connection() #self.assertRaises(scalaris.ConnectionError, t.write, str(self._testTime) + key, _TEST_DATA[0]) t.write(str(self._testTime) + key, _TEST_DATA[0]) t.close_connection()
def testWriteString_NotFound(self): key = "_WriteString_notFound" t = Transaction() notFound = False try: t.read(str(self._testTime) + key) except scalaris.NotFoundError: notFound = True self.assertTrue(notFound) t.write(str(self._testTime) + key, _TEST_DATA[0]) self.assertEqual(t.read(str(self._testTime) + key), _TEST_DATA[0]) t.close_connection()
def testWriteList1(self): key = "_testWriteList1_" t = scalaris.Transaction() for i in xrange(0, len(_TEST_DATA) - 1, 2): t.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 = t.read(str(self._testTime) + key + str(i)) self.assertEqual(actual, [_TEST_DATA[i], _TEST_DATA[i + 1]]) # commit the transaction and try to read the data with a new one: t.commit() t.close_connection() t = Transaction() for i in xrange(0, len(_TEST_DATA), 2): actual = t.read(str(self._testTime) + key + str(i)) self.assertEqual(actual, [_TEST_DATA[i], _TEST_DATA[i + 1]]) t.close_connection()
def testWriteList1(self): key = "_testWriteList1_" t = scalaris.Transaction() for i in xrange(0, len(_TEST_DATA) - 1, 2): t.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 = t.read(str(self._testTime) + key + str(i)) self.assertEqual(actual, [_TEST_DATA[i], _TEST_DATA[i + 1]]) # commit the transaction and try to read the data with a new one: t.commit() t.close_connection() t = Transaction() for i in xrange(0, len(_TEST_DATA), 2): actual = t.read(str(self._testTime) + key + str(i)) self.assertEqual(actual, [_TEST_DATA[i], _TEST_DATA[i + 1]]) t.close_connection()
def testReqTooLarge(self): conn = Transaction() 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()
def _writeSingleTest(self, key, data): t = Transaction() t.write(str(self._testTime) + key, data) # now try to read the data: self.assertEqual(t.read(str(self._testTime) + key), data) # commit the transaction and try to read the data with a new one: t.commit() t.close_connection() t = Transaction() self.assertEqual(t.read(str(self._testTime) + key), data) t.close_connection()
def testDoubleClose(self): t = Transaction() t.close_connection() t.close_connection()
def testWriteString(self): key = "_testWriteString1_" t = Transaction() for i in xrange(len(_TEST_DATA)): t.write(str(self._testTime) + key + str(i), _TEST_DATA[i]) # now try to read the data: for i in xrange(len(_TEST_DATA)): actual = t.read(str(self._testTime) + key + str(i)) self.assertEqual(actual, _TEST_DATA[i]) # commit the transaction and try to read the data with a new one: t.commit() t.close_connection() t = Transaction() for i in xrange(len(_TEST_DATA)): actual = t.read(str(self._testTime) + key + str(i)) self.assertEqual(actual, _TEST_DATA[i]) t.close_connection()
def testAbort_NotConnected(self): t = Transaction() t.close_connection() #self.assertRaises(scalaris.ConnectionError, t.abort) t.abort() t.close_connection()
def testCommit_Empty(self): t = Transaction() t.commit() t.close_connection()
def testAbort_Empty(self): t = Transaction() t.abort() t.close_connection()
def testTransaction3(self): t = Transaction(conn=scalaris.JSONConnection(url=scalaris.DEFAULT_URL)) t.close_connection()
def testTransaction3(self): t = Transaction(conn = scalaris.JSONConnection(url = scalaris.DEFAULT_URL)) t.close_connection()
def testReqList_Empty(self): conn = Transaction() conn.req_list(conn.new_req_list()) conn.close_connection()
def testReqList1(self): key = "_ReqList1_" conn = Transaction() readRequests = conn.new_req_list() firstWriteRequests = conn.new_req_list() writeRequests = conn.new_req_list() for i in xrange(0, len(_TEST_DATA)): if (i % 2) == 0: firstWriteRequests.add_write( str(self._testTime) + key + str(i), _TEST_DATA[i]) writeRequests.add_write( str(self._testTime) + key + str(i), _TEST_DATA[i]) readRequests.add_read(str(self._testTime) + key + str(i)) results = conn.req_list(firstWriteRequests) # evaluate the first write results: for i in xrange(0, firstWriteRequests.size()): conn.process_result_write(results[i]) requests = conn.new_req_list(readRequests).extend( writeRequests).add_commit() results = conn.req_list(requests) self.assertEqual(requests.size(), len(results)) # now evaluate the read results: for i in xrange(0, readRequests.size()): if (i % 2) == 0: actual = conn.process_result_read(results[i]) self.assertEqual(_TEST_DATA[i], actual) else: try: conn.process_result_read(results[i]) # a not found exception must be thrown self.fail('expected a NotFoundError') except scalaris.NotFoundError: pass # now evaluate the write results: for i in xrange(0, writeRequests.size()): pos = readRequests.size() + i conn.process_result_write(results[pos]) # once again test reads - now all reads should be successful results = conn.req_list(readRequests) self.assertEqual(readRequests.size(), len(results)) # now evaluate the read results: for i in xrange(0, readRequests.size()): actual = conn.process_result_read(results[i]) self.assertEqual(_TEST_DATA[i], actual) conn.close_connection()
def testReqList1(self): key = "_ReqList1_" conn = Transaction() readRequests = conn.new_req_list() firstWriteRequests = conn.new_req_list() writeRequests = conn.new_req_list() for i in xrange(0, len(_TEST_DATA)): if (i % 2) == 0: firstWriteRequests.add_write(str(self._testTime) + key + str(i), _TEST_DATA[i]) writeRequests.add_write(str(self._testTime) + key + str(i), _TEST_DATA[i]) readRequests.add_read(str(self._testTime) + key + str(i)) results = conn.req_list(firstWriteRequests) # evaluate the first write results: for i in xrange(0, firstWriteRequests.size()): conn.process_result_write(results[i]) requests = conn.new_req_list(readRequests).extend(writeRequests).add_commit() results = conn.req_list(requests) self.assertEqual(requests.size(), len(results)) # now evaluate the read results: for i in xrange(0, readRequests.size()): if (i % 2) == 0: actual = conn.process_result_read(results[i]) self.assertEqual(_TEST_DATA[i], actual) else: try: conn.process_result_read(results[i]) # a not found exception must be thrown self.fail('expected a NotFoundError') except scalaris.NotFoundError: pass # now evaluate the write results: for i in xrange(0, writeRequests.size()): pos = readRequests.size() + i conn.process_result_write(results[pos]) # once again test reads - now all reads should be successful results = conn.req_list(readRequests) self.assertEqual(readRequests.size(), len(results)) # now evaluate the read results: for i in xrange(0, readRequests.size()): actual = conn.process_result_read(results[i]) self.assertEqual(_TEST_DATA[i], actual) conn.close_connection();
def testTransaction1(self): t = Transaction() t.close_connection()