crate 1.0.0.dev1__py3-none-any.whl → 1.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,290 +0,0 @@
1
- # -*- coding: utf-8; -*-
2
- #
3
- # Licensed to CRATE Technology GmbH ("Crate") under one or more contributor
4
- # license agreements. See the NOTICE file distributed with this work for
5
- # additional information regarding copyright ownership. Crate licenses
6
- # this file to you under the Apache License, Version 2.0 (the "License");
7
- # you may not use this file except in compliance with the License. You may
8
- # obtain a copy of the License at
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing, software
13
- # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14
- # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15
- # License for the specific language governing permissions and limitations
16
- # under the License.
17
- #
18
- # However, if you have executed another commercial license agreement
19
- # with Crate these terms will supersede the license and you may use the
20
- # software solely pursuant to the terms of the relevant commercial agreement.
21
- import json
22
- import os
23
- import tempfile
24
- import urllib
25
- from verlib2 import Version
26
- from unittest import TestCase, mock
27
- from io import BytesIO
28
-
29
- import urllib3
30
-
31
- import crate
32
- from .layer import CrateLayer, prepend_http, http_url_from_host_port, wait_for_http_url
33
- from .settings import crate_path
34
-
35
-
36
- class LayerUtilsTest(TestCase):
37
-
38
- def test_prepend_http(self):
39
- host = prepend_http('localhost')
40
- self.assertEqual('http://localhost', host)
41
- host = prepend_http('http://localhost')
42
- self.assertEqual('http://localhost', host)
43
- host = prepend_http('https://localhost')
44
- self.assertEqual('https://localhost', host)
45
- host = prepend_http('http')
46
- self.assertEqual('http://http', host)
47
-
48
- def test_http_url(self):
49
- url = http_url_from_host_port(None, None)
50
- self.assertEqual(None, url)
51
- url = http_url_from_host_port('localhost', None)
52
- self.assertEqual(None, url)
53
- url = http_url_from_host_port(None, 4200)
54
- self.assertEqual(None, url)
55
- url = http_url_from_host_port('localhost', 4200)
56
- self.assertEqual('http://localhost:4200', url)
57
- url = http_url_from_host_port('https://crate', 4200)
58
- self.assertEqual('https://crate:4200', url)
59
-
60
- def test_wait_for_http(self):
61
- log = BytesIO(b'[i.c.p.h.CrateNettyHttpServerTransport] [crate] publish_address {127.0.0.1:4200}')
62
- addr = wait_for_http_url(log)
63
- self.assertEqual('http://127.0.0.1:4200', addr)
64
- log = BytesIO(b'[i.c.p.h.CrateNettyHttpServerTransport] [crate] publish_address {}')
65
- addr = wait_for_http_url(log=log, timeout=1)
66
- self.assertEqual(None, addr)
67
-
68
- @mock.patch.object(crate.testing.layer, "_download_and_extract", lambda uri, directory: None)
69
- def test_layer_from_uri(self):
70
- """
71
- The CrateLayer can also be created by providing an URI that points to
72
- a CrateDB tarball.
73
- """
74
- with urllib.request.urlopen("https://crate.io/versions.json") as response:
75
- versions = json.loads(response.read().decode())
76
- version = versions["crate_testing"]
77
-
78
- self.assertGreaterEqual(Version(version), Version("4.5.0"))
79
-
80
- uri = "https://cdn.crate.io/downloads/releases/crate-{}.tar.gz".format(version)
81
- layer = CrateLayer.from_uri(uri, name="crate-by-uri", http_port=42203)
82
- self.assertIsInstance(layer, CrateLayer)
83
-
84
- @mock.patch.dict('os.environ', {}, clear=True)
85
- def test_java_home_env_not_set(self):
86
- with tempfile.TemporaryDirectory() as tmpdir:
87
- layer = CrateLayer('java-home-test', tmpdir)
88
- # JAVA_HOME must not be set to `None`, since it would be interpreted as a
89
- # string 'None', and therefore intepreted as a path
90
- self.assertEqual(layer.env['JAVA_HOME'], '')
91
-
92
- @mock.patch.dict('os.environ', {}, clear=True)
93
- def test_java_home_env_set(self):
94
- java_home = '/usr/lib/jvm/java-11-openjdk-amd64'
95
- with tempfile.TemporaryDirectory() as tmpdir:
96
- os.environ['JAVA_HOME'] = java_home
97
- layer = CrateLayer('java-home-test', tmpdir)
98
- self.assertEqual(layer.env['JAVA_HOME'], java_home)
99
-
100
- @mock.patch.dict('os.environ', {}, clear=True)
101
- def test_java_home_env_override(self):
102
- java_11_home = '/usr/lib/jvm/java-11-openjdk-amd64'
103
- java_12_home = '/usr/lib/jvm/java-12-openjdk-amd64'
104
- with tempfile.TemporaryDirectory() as tmpdir:
105
- os.environ['JAVA_HOME'] = java_11_home
106
- layer = CrateLayer('java-home-test', tmpdir, env={'JAVA_HOME': java_12_home})
107
- self.assertEqual(layer.env['JAVA_HOME'], java_12_home)
108
-
109
-
110
- class LayerTest(TestCase):
111
-
112
- def test_basic(self):
113
- """
114
- This layer starts and stops a ``Crate`` instance on a given host, port,
115
- a given crate node name and, optionally, a given cluster name::
116
- """
117
-
118
- port = 44219
119
- transport_port = 44319
120
-
121
- layer = CrateLayer('crate',
122
- crate_home=crate_path(),
123
- host='127.0.0.1',
124
- port=port,
125
- transport_port=transport_port,
126
- cluster_name='my_cluster'
127
- )
128
-
129
- # The working directory is defined on layer instantiation.
130
- # It is sometimes required to know it before starting the layer.
131
- self.assertRegex(layer.wdPath(), r".+/crate_layer/crate")
132
-
133
- # Start the layer.
134
- layer.start()
135
-
136
- # The urls of the crate servers to be instantiated can be obtained
137
- # via `crate_servers`.
138
- self.assertEqual(layer.crate_servers, ["http://127.0.0.1:44219"])
139
-
140
- # Access the CrateDB instance on the HTTP interface.
141
-
142
- http = urllib3.PoolManager()
143
-
144
- stats_uri = "http://127.0.0.1:{0}/".format(port)
145
- response = http.request('GET', stats_uri)
146
- self.assertEqual(response.status, 200)
147
-
148
- # The layer can be shutdown using its `stop()` method.
149
- layer.stop()
150
-
151
- def test_dynamic_http_port(self):
152
- """
153
- It is also possible to define a port range instead of a static HTTP port for the layer.
154
-
155
- Crate will start with the first available port in the given range and the test
156
- layer obtains the chosen port from the startup logs of the Crate process.
157
- Note, that this feature requires a logging configuration with at least loglevel
158
- ``INFO`` on ``http``.
159
- """
160
- port = '44200-44299'
161
- layer = CrateLayer('crate', crate_home=crate_path(), port=port)
162
- layer.start()
163
- self.assertRegex(layer.crate_servers[0], r"http://127.0.0.1:442\d\d")
164
- layer.stop()
165
-
166
- def test_default_settings(self):
167
- """
168
- Starting a CrateDB layer leaving out optional parameters will apply the following
169
- defaults.
170
-
171
- The default http port is the first free port in the range of ``4200-4299``,
172
- the default transport port is the first free port in the range of ``4300-4399``,
173
- the host defaults to ``127.0.0.1``.
174
-
175
- The command to call is ``bin/crate`` inside the ``crate_home`` path.
176
- The default config file is ``config/crate.yml`` inside ``crate_home``.
177
- The default cluster name will be auto generated using the HTTP port.
178
- """
179
- layer = CrateLayer('crate_defaults', crate_home=crate_path())
180
- layer.start()
181
- self.assertEqual(layer.crate_servers[0], "http://127.0.0.1:4200")
182
- layer.stop()
183
-
184
- def test_additional_settings(self):
185
- """
186
- The ``Crate`` layer can be started with additional settings as well.
187
- Add a dictionary for keyword argument ``settings`` which contains your settings.
188
- Those additional setting will override settings given as keyword argument.
189
-
190
- The settings will be handed over to the ``Crate`` process with the ``-C`` flag.
191
- So the setting ``threadpool.bulk.queue_size: 100`` becomes
192
- the command line flag: ``-Cthreadpool.bulk.queue_size=100``::
193
- """
194
- layer = CrateLayer(
195
- 'custom',
196
- crate_path(),
197
- port=44401,
198
- settings={
199
- "cluster.graceful_stop.min_availability": "none",
200
- "http.port": 44402
201
- }
202
- )
203
- layer.start()
204
- self.assertEqual(layer.crate_servers[0], "http://127.0.0.1:44402")
205
- self.assertIn("-Ccluster.graceful_stop.min_availability=none", layer.start_cmd)
206
- layer.stop()
207
-
208
- def test_verbosity(self):
209
- """
210
- The test layer hides the standard output of Crate per default. To increase the
211
- verbosity level the additional keyword argument ``verbose`` needs to be set
212
- to ``True``::
213
- """
214
- layer = CrateLayer('crate',
215
- crate_home=crate_path(),
216
- verbose=True)
217
- layer.start()
218
- self.assertTrue(layer.verbose)
219
- layer.stop()
220
-
221
- def test_environment_variables(self):
222
- """
223
- It is possible to provide environment variables for the ``Crate`` testing
224
- layer.
225
- """
226
- layer = CrateLayer('crate',
227
- crate_home=crate_path(),
228
- env={"CRATE_HEAP_SIZE": "300m"})
229
-
230
- layer.start()
231
-
232
- sql_uri = layer.crate_servers[0] + "/_sql"
233
-
234
- http = urllib3.PoolManager()
235
- response = http.urlopen('POST', sql_uri,
236
- body='{"stmt": "select heap[\'max\'] from sys.nodes"}')
237
- json_response = json.loads(response.data.decode('utf-8'))
238
-
239
- self.assertEqual(json_response["rows"][0][0], 314572800)
240
-
241
- layer.stop()
242
-
243
- def test_cluster(self):
244
- """
245
- To start a cluster of ``Crate`` instances, give each instance the same
246
- ``cluster_name``. If you want to start instances on the same machine then
247
- use value ``_local_`` for ``host`` and give every node different ports::
248
- """
249
- cluster_layer1 = CrateLayer(
250
- 'crate1',
251
- crate_path(),
252
- host='_local_',
253
- cluster_name='my_cluster',
254
- )
255
- cluster_layer2 = CrateLayer(
256
- 'crate2',
257
- crate_path(),
258
- host='_local_',
259
- cluster_name='my_cluster',
260
- settings={"discovery.initial_state_timeout": "10s"}
261
- )
262
-
263
- # If we start both layers, they will, after a small amount of time, find each other
264
- # and form a cluster.
265
- cluster_layer1.start()
266
- cluster_layer2.start()
267
-
268
- # We can verify that by checking the number of nodes a node knows about.
269
- http = urllib3.PoolManager()
270
-
271
- def num_cluster_nodes(crate_layer):
272
- sql_uri = crate_layer.crate_servers[0] + "/_sql"
273
- response = http.urlopen('POST', sql_uri, body='{"stmt":"select count(*) from sys.nodes"}')
274
- json_response = json.loads(response.data.decode('utf-8'))
275
- return json_response["rows"][0][0]
276
-
277
- # We might have to wait a moment before the cluster is finally created.
278
- num_nodes = num_cluster_nodes(cluster_layer1)
279
- import time
280
- retries = 0
281
- while num_nodes < 2: # pragma: no cover
282
- time.sleep(1)
283
- num_nodes = num_cluster_nodes(cluster_layer1)
284
- retries += 1
285
- if retries == 30:
286
- break
287
- self.assertEqual(num_nodes, 2)
288
-
289
- cluster_layer1.stop()
290
- cluster_layer2.stop()
crate/testing/tests.py DELETED
@@ -1,34 +0,0 @@
1
- # vi: set encoding=utf-8
2
- # -*- coding: utf-8; -*-
3
- #
4
- # Licensed to CRATE Technology GmbH ("Crate") under one or more contributor
5
- # license agreements. See the NOTICE file distributed with this work for
6
- # additional information regarding copyright ownership. Crate licenses
7
- # this file to you under the Apache License, Version 2.0 (the "License");
8
- # you may not use this file except in compliance with the License. You may
9
- # obtain a copy of the License at
10
- #
11
- # http://www.apache.org/licenses/LICENSE-2.0
12
- #
13
- # Unless required by applicable law or agreed to in writing, software
14
- # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15
- # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16
- # License for the specific language governing permissions and limitations
17
- # under the License.
18
- #
19
- # However, if you have executed another commercial license agreement
20
- # with Crate these terms will supersede the license and you may use the
21
- # software solely pursuant to the terms of the relevant commercial agreement.
22
-
23
- import unittest
24
- from .test_layer import LayerUtilsTest, LayerTest
25
-
26
-
27
- makeSuite = unittest.TestLoader().loadTestsFromTestCase
28
-
29
-
30
- def test_suite():
31
- suite = unittest.TestSuite()
32
- suite.addTest(makeSuite(LayerUtilsTest))
33
- suite.addTest(makeSuite(LayerTest))
34
- return suite
@@ -1 +0,0 @@
1
- import sys, types, os;has_mfs = sys.version_info > (3, 5);p = os.path.join(sys._getframe(1).f_locals['sitedir'], *('crate',));importlib = has_mfs and __import__('importlib.util');has_mfs and __import__('importlib.machinery');m = has_mfs and sys.modules.setdefault('crate', importlib.util.module_from_spec(importlib.machinery.PathFinder.find_spec('crate', [os.path.dirname(p)])));m = m or sys.modules.setdefault('crate', types.ModuleType('crate'));mp = (m or []) and m.__dict__.setdefault('__path__',[]);(p not in mp) and mp.append(p)
@@ -1,29 +0,0 @@
1
- crate-1.0.0.dev1-py3.9-nspkg.pth,sha256=nqN0-lx5dVfXKgm9N7WRgI0lrvtTYi2PUOtTjfAMtjY,534
2
- crate/client/__init__.py,sha256=GnUvV93BwWcsazbCFyfnF4MqJivTNZOcEzHcR3sAzDc,1308
3
- crate/client/_pep440.py,sha256=iwY5wopxbgbwsT0ImANrwN3V_ZYQHhSr7lEdVT5dQRM,42
4
- crate/client/blob.py,sha256=plTwGEULg5s1VdKIMW6a0Zljdkng7xw0WXkXyiwNaSU,3496
5
- crate/client/connection.py,sha256=5vmtGZF20vxoeExHTeQ-DqJX4BPNT8ebzH_HOvdcqdE,8432
6
- crate/client/converter.py,sha256=9_-FBp8l9LwCfBsoWO0YOW0ASkwJ-le-YJFfJMLKCew,4301
7
- crate/client/cursor.py,sha256=qnrNM9QDQgo9RFVGU7HPmCxK15EFUWiOxW3BNlZcuNw,10758
8
- crate/client/exceptions.py,sha256=or3D-AzKRKKgrOa8lAUIk6CFObdXvXZmfV1MMlzNP8o,2409
9
- crate/client/http.py,sha256=aA6L-9i7-UovLKG3ICymRq7S0KPOIZiNejv1jzPrn4A,22559
10
- crate/client/test_connection.py,sha256=sGsnqgpxe9sgD6TllVbQGHozf4Binrzxe_ydfAQJgWE,3670
11
- crate/client/test_cursor.py,sha256=Q9Npq55zTY4g51kf3P7DnmTsYdv0iRwqDptKOj9ffxA,12858
12
- crate/client/test_exceptions.py,sha256=LdTfl4mV5fjxROKeo6_x2xtff0b3tWy4IPN3BLDhVeA,352
13
- crate/client/test_http.py,sha256=LvUC0QeAhH2-LJDfp2zVT6OEVTG6GKqid6qUTM9rjGY,23534
14
- crate/client/test_util.py,sha256=k8j3Ya1fPwdfrbRkUNsqxqcyoi5Rj7O_r4HpOEdK_yA,2508
15
- crate/client/tests.py,sha256=dWNezqJdr0YBZNgxrChFTbaNh_DTesU2vNgm2UGxDE0,11165
16
- crate/testing/__init__.py,sha256=UnxmjVrk-eNORsitiM48W0pB6yfsaErOak8RYh_ELt8,10
17
- crate/testing/layer.py,sha256=-AvRsTysqncns5IqUFWKZFppC3KwQxDJt0tnBWjxlMs,13382
18
- crate/testing/settings.py,sha256=YTqod79NO4Lv_agPgMLGlB_fMe6baAhLXFKBZnuytBk,1652
19
- crate/testing/test_datetime_old.py,sha256=SI0HzI8CfcbOYIj9MJz_XACrnwWyMQCZzM_Gu5PUDkI,3799
20
- crate/testing/test_layer.py,sha256=S0QgY7TgD52EyYWrMoSLUfRVjVzw-oiUdR-g5fJ_zmQ,11512
21
- crate/testing/tests.py,sha256=4YcBkpRnihPHPJnr6wPcmORfzkI7FSVL2TCm4MdzUss,1327
22
- crate/testing/util.py,sha256=qtc72rKfvfTA9VMKjE2JSukffobd7ffCcddoTiAdO6A,690
23
- crate-1.0.0.dev1.dist-info/LICENSE,sha256=1QGh4tR_JmDKn33ztoDv2UkER0Q4Zh1kC5J3vMWwRso,12854
24
- crate-1.0.0.dev1.dist-info/METADATA,sha256=6NMZWvLEo0YVfyez5stR6m1-crw1MIdzr-ucOuXMJv8,5371
25
- crate-1.0.0.dev1.dist-info/NOTICE,sha256=vwbBS8sykCOndA1kjuu8dUInljH27kk3lcPBzQ2SMns,1159
26
- crate-1.0.0.dev1.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
27
- crate-1.0.0.dev1.dist-info/namespace_packages.txt,sha256=2wP2HlpxdhgTLMl9ipi168xkm6FMq9_2bf0xGGxF_OI,6
28
- crate-1.0.0.dev1.dist-info/top_level.txt,sha256=2wP2HlpxdhgTLMl9ipi168xkm6FMq9_2bf0xGGxF_OI,6
29
- crate-1.0.0.dev1.dist-info/RECORD,,
@@ -1 +0,0 @@
1
- crate