aboutsummaryrefslogtreecommitdiff
path: root/k2v_test.py
blob: 3219056ef3aee67e355b31ecb20057836b0338d2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/usr/bin/env python

import os
import requests
from datetime import datetime

# let's talk to our AWS Elasticsearch cluster
#from requests_aws4auth import AWS4Auth
#auth = AWS4Auth('GK31c2f218a2e44f485b94239e',
#                       'b892c0665f0ada8a4755dae98baa3b133590e11dae3bcc1f9d769d67f16c3835',
#                       'us-east-1',
#                       's3')

from aws_requests_auth.aws_auth import AWSRequestsAuth
auth = AWSRequestsAuth(aws_access_key='GK31c2f218a2e44f485b94239e',
        aws_secret_access_key='b892c0665f0ada8a4755dae98baa3b133590e11dae3bcc1f9d769d67f16c3835',
        aws_host='localhost:3812',
        aws_region='us-east-1',
        aws_service='k2v')


print("-- ReadIndex")
response = requests.get('http://localhost:3812/alex',
                        auth=auth)
print(response.headers)
print(response.text)


sort_keys = ["a", "b", "c", "d"]

for sk in sort_keys:
    print("-- (%s) Put initial (no CT)"%sk)
    response = requests.put('http://localhost:3812/alex/root?sort_key=%s'%sk,
                            auth=auth,
                            data='{}: Hello, world!'.format(datetime.timestamp(datetime.now())))
    print(response.headers)
    print(response.text)

    print("-- Get")
    response = requests.get('http://localhost:3812/alex/root?sort_key=%s'%sk,
                            auth=auth)
    print(response.headers)
    print(response.text)
    ct = response.headers["x-garage-causality-token"]

    print("-- ReadIndex")
    response = requests.get('http://localhost:3812/alex',
                            auth=auth)
    print(response.headers)
    print(response.text)

    print("-- Put with CT")
    response = requests.put('http://localhost:3812/alex/root?sort_key=%s'%sk,
                            auth=auth,
                            headers={'x-garage-causality-token': ct},
                            data='{}: Good bye, world!'.format(datetime.timestamp(datetime.now())))
    print(response.headers)
    print(response.text)

    print("-- Get")
    response = requests.get('http://localhost:3812/alex/root?sort_key=%s'%sk,
                            auth=auth)
    print(response.headers)
    print(response.text)

    print("-- Put again with same CT (concurrent)")
    response = requests.put('http://localhost:3812/alex/root?sort_key=%s'%sk,
                            auth=auth,
                            headers={'x-garage-causality-token': ct},
                            data='{}: Concurrent value, oops'.format(datetime.timestamp(datetime.now())))
    print(response.headers)
    print(response.text)

for sk in sort_keys:
    print("-- (%s) Get"%sk)
    response = requests.get('http://localhost:3812/alex/root?sort_key=%s'%sk,
                            auth=auth)
    print(response.headers)
    print(response.text)
    ct = response.headers["x-garage-causality-token"]

    print("-- Delete")
    response = requests.delete('http://localhost:3812/alex/root?sort_key=%s'%sk,
                            headers={'x-garage-causality-token': ct},
                            auth=auth)
    print(response.headers)
    print(response.text)

print("-- ReadIndex")
response = requests.get('http://localhost:3812/alex',
                        auth=auth)
print(response.headers)
print(response.text)

print("-- InsertBatch")
response = requests.post('http://localhost:3812/alex',
                        auth=auth,
                        data='''
[
    {"pk": "root", "sk": "a", "ct": null, "v": "aW5pdGlhbCB0ZXN0Cg=="},
    {"pk": "root", "sk": "b", "ct": null, "v": "aW5pdGlhbCB0ZXN1Cg=="},
    {"pk": "root", "sk": "c", "ct": null, "v": "aW5pdGlhbCB0ZXN2Cg=="}
]
''')
print(response.headers)
print(response.text)

print("-- ReadIndex")
response = requests.get('http://localhost:3812/alex',
                        auth=auth)
print(response.headers)
print(response.text)

for sk in sort_keys:
    print("-- (%s) Get"%sk)
    response = requests.get('http://localhost:3812/alex/root?sort_key=%s'%sk,
                            auth=auth)
    print(response.headers)
    print(response.text)
    ct = response.headers["x-garage-causality-token"]

print("-- ReadBatch")
response = requests.post('http://localhost:3812/alex?search',
                        auth=auth,
                        data='''
[
    {"partitionKey": "root"},
    {"partitionKey": "root", "tombstones": true},
    {"partitionKey": "root", "tombstones": true, "limit": 2},
    {"partitionKey": "root", "start": "c", "singleItem": true},
    {"partitionKey": "root", "start": "b", "end": "d", "tombstones": true}
]
''')
print(response.headers)
print(response.text)


print("-- DeleteBatch")
response = requests.post('http://localhost:3812/alex?delete',
                        auth=auth,
                        data='''
[
    {"partitionKey": "root", "start": "b", "end": "c"}
]
''')
print(response.headers)
print(response.text)

print("-- ReadBatch")
response = requests.post('http://localhost:3812/alex?search',
                        auth=auth,
                        data='''
[
    {"partitionKey": "root"}
]
''')
print(response.headers)
print(response.text)