Skip to content

Commit 3cfb676

Browse files
committed
Merge pull request #1512 from dhermes/bigtable-basis-sys-test
Introducing basic system test for Bigtable.
2 parents e3f45fd + b223311 commit 3cfb676

2 files changed

Lines changed: 98 additions & 0 deletions

File tree

system_tests/bigtable.py

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# Copyright 2016 Google Inc. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import time
16+
17+
import unittest2
18+
19+
from gcloud import _helpers
20+
from gcloud.bigtable.client import Client
21+
from gcloud.environment_vars import TESTS_PROJECT
22+
23+
24+
_helpers.PROJECT = TESTS_PROJECT
25+
CENTRAL_1C_ZONE = 'us-central1-c'
26+
NOW_MILLIS = int(1000 * time.time())
27+
CLUSTER_ID = 'gcloud-python-%d' % (NOW_MILLIS,)
28+
EXISTING_CLUSTERS = []
29+
EXPECTED_ZONES = (
30+
'asia-east1-b',
31+
'europe-west1-c',
32+
'us-central1-b',
33+
CENTRAL_1C_ZONE,
34+
)
35+
36+
37+
class Config(object):
38+
"""Run-time configuration to be modified at set-up.
39+
40+
This is a mutable stand-in to allow test set-up to modify
41+
global state.
42+
"""
43+
CLIENT = None
44+
CLUSTER = None
45+
46+
47+
def setUpModule():
48+
Config.CLIENT = Client(admin=True)
49+
Config.CLUSTER = Config.CLIENT.cluster(CENTRAL_1C_ZONE, CLUSTER_ID,
50+
display_name=CLUSTER_ID)
51+
Config.CLIENT.start()
52+
clusters, failed_zones = Config.CLIENT.list_clusters()
53+
54+
if len(failed_zones) != 0:
55+
raise ValueError('List clusters failed in module set up.')
56+
57+
EXISTING_CLUSTERS[:] = clusters
58+
59+
# After listing, create the test cluster.
60+
created_op = Config.CLUSTER.create()
61+
total_sleep = 0
62+
while not created_op.finished():
63+
if total_sleep > 5:
64+
raise RuntimeError('Cluster creation exceed 5 seconds.')
65+
time.sleep(1)
66+
total_sleep += 1
67+
68+
69+
def tearDownModule():
70+
Config.CLUSTER.delete()
71+
Config.CLIENT.stop()
72+
73+
74+
class TestClusterAdminAPI(unittest2.TestCase):
75+
76+
def setUp(self):
77+
self.clusters_to_delete = []
78+
79+
def tearDown(self):
80+
for cluster in self.clusters_to_delete:
81+
cluster.delete()
82+
83+
def test_list_zones(self):
84+
zones = Config.CLIENT.list_zones()
85+
self.assertEqual(sorted(zones), sorted(EXPECTED_ZONES))
86+
87+
def test_list_clusters(self):
88+
clusters, failed_zones = Config.CLIENT.list_clusters()
89+
self.assertEqual(failed_zones, [])
90+
# We have added one new cluster in `setUpModule`.
91+
self.assertEqual(len(clusters), len(EXISTING_CLUSTERS) + 1)
92+
for cluster in clusters:
93+
cluster_existence = (cluster in EXISTING_CLUSTERS or
94+
cluster == Config.CLUSTER)
95+
self.assertTrue(cluster_existence)

system_tests/run_system_test.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
# This assumes the command is being run via tox hence the
2020
# repository root is the current directory.
2121
import bigquery
22+
import bigtable
2223
import datastore
2324
import pubsub
2425
import storage
@@ -30,12 +31,14 @@
3031
'storage': ['project', 'credentials'],
3132
'pubsub': ['project', 'credentials'],
3233
'bigquery': ['project', 'credentials'],
34+
'bigtable': ['project', 'credentials'],
3335
}
3436
TEST_MODULES = {
3537
'datastore': datastore,
3638
'storage': storage,
3739
'pubsub': pubsub,
3840
'bigquery': bigquery,
41+
'bigtable': bigtable,
3942
}
4043

4144

0 commit comments

Comments
 (0)