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()
Beispiel #2
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()
    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()
Beispiel #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()
Beispiel #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()
    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()
    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()
Beispiel #8
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()
    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()
Beispiel #10
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()
#    distributed under the License is distributed on an "AS IS" BASIS,
#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#    See the License for the specific language governing permissions and
#    limitations under the License.

from scalaris import TransactionSingleOp, ReplicatedDHT, PubSub
from scalaris import ConnectionError, TimeoutError, NotFoundError, AbortError, KeyChangedError, UnknownError
import scalaris_bench
import sys

if __name__ == "__main__":
    if (len(sys.argv) == 3 and sys.argv[1] in ["--read", "-r"]):
        sc = TransactionSingleOp()
        key = sys.argv[2]
        try:
            value = sc.read(key)
            print 'read(' + key + ') = ' + repr(value)
        except ConnectionError as instance:
            print 'read(' + key + ') failed with connection error'
            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()
#    distributed under the License is distributed on an "AS IS" BASIS,
#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#    See the License for the specific language governing permissions and
#    limitations under the License.

from scalaris import TransactionSingleOp, ReplicatedDHT
from scalaris import ConnectionError, TimeoutError, NotFoundError, AbortError, KeyChangedError, UnknownError
import scalaris_bench
import sys

if __name__ == "__main__":
    if (len(sys.argv) == 3 and sys.argv[1] in ["--read", "-r"]):
        sc = TransactionSingleOp()
        key = sys.argv[2]
        try:
            value = sc.read(key)
            print 'read(' + key + ') = ' + repr(value)
        except ConnectionError as instance:
            print 'read(' + key + ') failed with connection error'
            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()