def _transIncrementBench3(testruns, name): key = str(_benchTime) + name results = [] for i in xrange(testruns): for retry in xrange(3): try: key_i = key + str(i) tx_init = scalaris.Transaction() tx_init.write(key_i, 0) tx_init.commit() tx_init.close_connection() _testBegin() tx = scalaris.Transaction() for _j in xrange(_TRANSACTIONS_PER_TESTRUN): value_old = tx.read(key_i) tx.write(key_i, value_old + 1) tx.commit() tx.close_connection() results.append(_testEnd(_TRANSACTIONS_PER_TESTRUN)) break except: # _printException() if (retry == 2): return -1 return _getAvgSpeed(results)
def pre_init(self, j = None): if j is None: return tx_init = scalaris.Transaction(conn = _getConnection()) reqs = tx_init.new_req_list() reqs.add_write(self._key + '_' + str(j), self._value_init).add_commit() results = tx_init.req_list(reqs) tx_init.process_result_write(results[0]) tx_init.close_connection()
def pre_init(self, j = None): value_init = [] for i in xrange(len(self._keys)): value_init.append(_getRandom(_BENCH_DATA_SIZE, type(self._value).__name__)) tx_init = scalaris.Transaction(conn = _getConnection()) reqs = tx_init.new_req_list() for i in xrange(len(self._keys)): reqs.add_write(self._keys[i], value_init[i]) reqs.add_commit() results = tx_init.req_list(reqs) for i in xrange(len(self._keys)): tx_init.process_result_write(results[i]) tx_init.close_connection()
def _transBench3(testruns, value, name): key = str(_benchTime) + name results = [] for i in xrange(testruns): for retry in xrange(3): try: _testBegin() tx = scalaris.Transaction() for j in xrange(_TRANSACTIONS_PER_TESTRUN): tx.write(key + str(i) + str(j), value) tx.commit() tx.close_connection() results.append(_testEnd(_TRANSACTIONS_PER_TESTRUN)) break except: # _printException() if (retry == 2): return -1 return _getAvgSpeed(results)
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 init(self): self._tx = scalaris.Transaction(conn = _getConnection())
def operation(self, j): tx = scalaris.Transaction(conn = self._connection) self.operation2(tx, j)
def operation(self, j): tx = scalaris.Transaction(conn = _getConnection()) self.operation2(tx, j) tx.close_connection()
def pre_init(self, j = None): tx_init = scalaris.Transaction(conn = _getConnection()) tx_init.write(self._key, 0) tx_init.commit() tx_init.close_connection()
def operation(self, j): tx = scalaris.Transaction(conn = self._connection) tx.write(self._key + '_' + str(j), self._value) tx.commit()
# use compact JSON encoding: params_json = json.dumps(params, separators=(',', ':')) print '' print 'request:' print json.dumps(params, indent=1) headers = {"Content-type": "application/json"} try: self._conn.request("POST", scalaris.DEFAULT_PATH, params_json, headers) response = self._conn.getresponse() if (response.status < 200 or response.status >= 300): raise scalaris.ConnectionError(response) data = response.read() except Exception as instance: raise scalaris.ConnectionError(instance) print '' print 'response:' print json.dumps(json.loads(data), indent=1) response_json = json.loads(data) return response_json['result'] if __name__ == "__main__": sc1 = scalaris.Transaction(conn=ConnectionWithTrace()) sc1.req_list(sc1.new_req_list().add_write("keyA", "valueA").add_write( "keyB", "valueB").add_commit()) sc1.close_connection() sc2 = scalaris.Transaction(conn=ConnectionWithTrace()) sc2.req_list(sc2.new_req_list().add_read("keyA").add_read("keyB")) sc2.req_list(sc2.new_req_list().add_write("keyA", "valueA2").add_commit())