コード例 #1
0
ファイル: test_correctness.py プロジェクト: jl3953/smdbrpc
 def test_simple_write(self):
     key1 = 1994813
     key2 = 20200604
     response = self.stub.ContactHotshard(
         smdbrpc_pb2.HotshardRequest(
             hlctimestamp=smdbrpc_pb2.HLCTimestamp(
                 walltime=self.now + 100,
                 logicaltime=0,
             ),
             write_keyset=[
                 smdbrpc_pb2.KVPair(key=key1, value=key1),
                 smdbrpc_pb2.KVPair(key=key2, value=key2),
             ],
             read_keyset=[],
         ))
     self.assertTrue(response.is_committed)
     response = self.stub.ContactHotshard(
         smdbrpc_pb2.HotshardRequest(
             hlctimestamp=smdbrpc_pb2.HLCTimestamp(
                 walltime=self.now + 200,
                 logicaltime=0,
             ),
             write_keyset=[],
             read_keyset=[key1, key2],
         ))
     self.assertTrue(response.is_committed)
     self.assertEqual(2, len(response.read_valueset))
     self.assertEqual(key1, response.read_valueset[0].value)
     self.assertEqual(key2, response.read_valueset[1].value)
コード例 #2
0
ファイル: test_correctness.py プロジェクト: jl3953/smdbrpc
 def test_succeed_on_non_recent_read(self):
     key = 1994217
     response = self.stub.ContactHotshard(
         smdbrpc_pb2.HotshardRequest(
             hlctimestamp=smdbrpc_pb2.HLCTimestamp(
                 walltime=self.now + 100,
                 logicaltime=0,
             ),
             write_keyset=[smdbrpc_pb2.KVPair(key=key, value=key)],
             read_keyset=[],
         ))
     self.assertTrue(response.is_committed)
     response = self.stub.ContactHotshard(
         smdbrpc_pb2.HotshardRequest(
             hlctimestamp=smdbrpc_pb2.HLCTimestamp(
                 walltime=self.now + 200,
                 logicaltime=0,
             ),
             write_keyset=[smdbrpc_pb2.KVPair(key=key, value=key + 1)],
             read_keyset=[],
         ))
     self.assertTrue(response.is_committed)
     response = self.stub.ContactHotshard(
         smdbrpc_pb2.HotshardRequest(
             hlctimestamp=smdbrpc_pb2.HLCTimestamp(
                 walltime=self.now + 150,
                 logicaltime=0,
             ),
             write_keyset=[],
             read_keyset=[key],
         ))
     self.assertTrue(response.is_committed)
     self.assertTrue(len(response.read_valueset), 1)
     self.assertEqual(key, response.read_valueset[0].value)
コード例 #3
0
ファイル: test_correctness.py プロジェクト: jl3953/smdbrpc
 def test_fail_on_write_between_disjoint_updates(self):
     key1 = 1994816
     key2 = 20200607
     response = self.stub.ContactHotshard(
         smdbrpc_pb2.HotshardRequest(
             hlctimestamp=smdbrpc_pb2.HLCTimestamp(
                 walltime=self.now + 100,
                 logicaltime=0,
             ),
             write_keyset=[
                 smdbrpc_pb2.KVPair(key=key1, value=key1),
                 smdbrpc_pb2.KVPair(key=key2, value=key2),
             ],
             read_keyset=[],
         ))
     self.assertTrue(response.is_committed)
     response = self.stub.ContactHotshard(
         smdbrpc_pb2.HotshardRequest(
             hlctimestamp=smdbrpc_pb2.HLCTimestamp(
                 walltime=self.now + 200,
                 logicaltime=0,
             ),
             write_keyset=[
                 smdbrpc_pb2.KVPair(key=key1, value=key1 + 1),
             ],
             read_keyset=[],
         ))
     self.assertTrue(response.is_committed)
     response = self.stub.ContactHotshard(
         smdbrpc_pb2.HotshardRequest(
             hlctimestamp=smdbrpc_pb2.HLCTimestamp(
                 walltime=self.now + 150,
                 logicaltime=0,
             ),
             write_keyset=[
                 smdbrpc_pb2.KVPair(key=key1, value=key1 + 10),
                 smdbrpc_pb2.KVPair(key=key2, value=key2 + 10)
             ],
             read_keyset=[],
         ))
     self.assertFalse(response.is_committed)
     response = self.stub.ContactHotshard(
         smdbrpc_pb2.HotshardRequest(
             hlctimestamp=smdbrpc_pb2.HLCTimestamp(
                 walltime=self.now + 300,
                 logicaltime=0,
             ),
             write_keyset=[],
             read_keyset=[key1, key2],
         ))
     self.assertTrue(response.is_committed)
     self.assertEqual(2, len(response.read_valueset))
     self.assertEqual(key1 + 1, response.read_valueset[0].value)
     self.assertEqual(key2, response.read_valueset[1].value)
コード例 #4
0
ファイル: client.py プロジェクト: jl3953/smdbrpc
def run():

    parser = argparse.ArgumentParser("sends a bunch of requests to a server")
    parser.add_argument("--num_keys",
                        type=int,
                        default=100,
                        help="number of keys to send")
    args = parser.parse_args()
    # NOTE(gRPC Python Team): .close() is possible on a channel and should be
    # used in circumstances in which the with statement does not fit the needs
    # of the code.
    with grpc.insecure_channel('localhost:50051') as channel:
        for i in range(args.num_keys):
            if i % 1000 == 0:
                print("Processed up to", i)
            stub = smdbrpc_pb2_grpc.HotshardGatewayStub(channel)
            response = stub.ContactHotshard(
                smdbrpc_pb2.HotshardRequest(
                    hlctimestamp=smdbrpc_pb2.HLCTimestamp(
                        walltime=time.time_ns(),
                        logicaltime=0,
                    ),
                    write_keyset=[smdbrpc_pb2.KVPair(key=i, value=i)],
                    read_keyset=[],
                ))
            if response.is_committed:
                read_response = stub.ContactHotshard(
                    smdbrpc_pb2.HotshardRequest(
                        hlctimestamp=smdbrpc_pb2.HLCTimestamp(
                            walltime=time.time_ns(),
                            logicaltime=1,
                        ),
                        write_keyset=[],
                        read_keyset=[i],
                    ))
                if read_response.is_committed:
                    if len(
                            read_response.read_valueset
                    ) == 1 and read_response.read_valueset[0].value == i:
                        continue
                    else:
                        print("Read empty on", i)
                        print("Read response", read_response)
                        raise BaseException
                else:
                    print("Read failed to commit on", i)
                    raise BaseException
            else:
                print("Write failed to commit on", i)
                raise BaseException

    print("Successfully wrote all {} keys!".format(args.num_keys))
コード例 #5
0
ファイル: test_correctness.py プロジェクト: jl3953/smdbrpc
 def test_fail_on_write_under_read(self):
     key = 1994216
     response = self.stub.ContactHotshard(
         smdbrpc_pb2.HotshardRequest(
             hlctimestamp=smdbrpc_pb2.HLCTimestamp(
                 walltime=self.now + 100,
                 logicaltime=0,
             ),
             write_keyset=[smdbrpc_pb2.KVPair(key=key, value=key)],
             read_keyset=[],
         ))
     self.assertTrue(response.is_committed)
     response = self.stub.ContactHotshard(
         smdbrpc_pb2.HotshardRequest(
             hlctimestamp=smdbrpc_pb2.HLCTimestamp(
                 walltime=self.now + 200,
                 logicaltime=0,
             ),
             write_keyset=[],
             read_keyset=[key],
         ))
     self.assertTrue(response.is_committed)
     self.assertEqual(1, len(response.read_valueset))
     self.assertEqual(key, response.read_valueset[0].value)
     response = self.stub.ContactHotshard(
         smdbrpc_pb2.HotshardRequest(
             hlctimestamp=smdbrpc_pb2.HLCTimestamp(
                 walltime=self.now + 150,
                 logicaltime=0,
             ),
             write_keyset=[smdbrpc_pb2.KVPair(key=key, value=key + 1)],
             read_keyset=[],
         ))
     self.assertFalse(response.is_committed)
     response = self.stub.ContactHotshard(
         smdbrpc_pb2.HotshardRequest(
             hlctimestamp=smdbrpc_pb2.HLCTimestamp(
                 walltime=self.now + 300,
                 logicaltime=0,
             ),
             write_keyset=[],
             read_keyset=[key],
         ))
     self.assertTrue(response.is_committed)
     self.assertTrue(1, len(response.read_valueset))
     self.assertEqual(key, response.read_valueset[0].value)
コード例 #6
0
ファイル: test_correctness.py プロジェクト: jl3953/smdbrpc
 def test_simple_read(self):
     key1 = 1994812
     key2 = 20200603
     response = self.stub.ContactHotshard(
         smdbrpc_pb2.HotshardRequest(
             hlctimestamp=smdbrpc_pb2.HLCTimestamp(
                 walltime=self.now + 100,
                 logicaltime=0,
             ),
             write_keyset=[],
             read_keyset=[key1, key2],
         ))
     self.assertTrue(response.is_committed)
     self.assertEqual(0, len(response.read_valueset))
コード例 #7
0
ファイル: test_correctness.py プロジェクト: jl3953/smdbrpc
 def test_simple_read(self):
     """
     Tests that reading an un-inserted value comes back empty.
     """
     key = 1994214
     response = self.stub.ContactHotshard(
         smdbrpc_pb2.HotshardRequest(
             hlctimestamp=smdbrpc_pb2.HLCTimestamp(
                 walltime=self.now + 100,
                 logicaltime=0,
             ),
             write_keyset=[],
             read_keyset=[key],
         ))
     self.assertTrue(response.is_committed)
     self.assertEqual(0, len(response.read_valueset))