Exemple #1
0
 def test_ping_restrict_services(self):
     services = [ServiceType.KeyValue]
     result = self.bucket.ping(PingOptions(service_types=services))
     keys = list(result.endpoints.keys())
     print(keys)
     self.assertEqual(1, len(keys))
     self.assertEqual(ServiceType.KeyValue, keys[0])
Exemple #2
0
 def test_ping_restrict_services(self):
     if self.is_mock:
         raise SkipTest("Mock -- skip cluster.ping() tests")
     services = [ServiceType.KeyValue]
     result = self.cluster.ping(PingOptions(service_types=services))
     keys = list(result.endpoints.keys())
     self.assertEqual(1, len(keys))
     self.assertEqual(ServiceType.KeyValue, keys[0])
Exemple #3
0
 def test_ping_timeout(self):
     self.skipIfMock()
     result = self.bucket.ping(
         PingOptions(timeout=timedelta(microseconds=1.0)))
     self.assertIsNotNone(result)
     for k, vals in result.endpoints.items():
         for v in vals:
             self.assertIsNotNone(v)
             self.assertIsNotNone(v.latency)
             self.assertIsNotNone(v.local)
             self.assertEqual(k, v.service_type)
             self.assertEqual(v.state, PingState.TIMEOUT)
def connect_to_cluster(host: str,
                       user: str,
                       password: str,
                       bucket: str,
                       services: List[ServiceType] = [ServiceType.Query]):
    """Creates a connection to a cluster and checks its connected to the given services before returning."""
    cluster = Cluster(host,
                      ClusterOptions(PasswordAuthenticator(user, password)))
    cb = cluster.bucket(bucket)  # pylint: disable=unused-variable
    for _ in range(100):
        result = cb.ping(PingOptions(service_types=services))
        ready = True
        for service in services:
            try:
                if result.endpoints[service][0].state != PingState.OK:
                    ready = False
            except (KeyError, IndexError) as e:
                raise AssertionError(
                    f"Service {service.value} not available") from e
        if ready:
            return cluster, cb
        time.sleep(1)
    raise AssertionError("Failed to connect to cluster")
Exemple #5
0
 def test_ping_report_id(self):
     report_id = "11111"
     result = self.bucket.ping(PingOptions(report_id=report_id))
     self.assertIn(report_id, result.id)
Exemple #6
0
bucket = cluster.bucket("beer-sample")
collection = bucket.default_collection()

# tag::cluster_ping_latency[]
ping_result = cluster.ping()

for endpoint, reports in ping_result.endpoints.items():
    for report in reports:
        print("{0}: {1} took {2}".format(endpoint.value, report.remote,
                                         report.latency))
# end::cluster_ping_latency[]

# tag::cluster_ping_as_json[]
ping_result = cluster.ping()
print(ping_result.as_json())
# end::cluster_ping_as_json[]

print("Cluster is okay? {}".format(ok(cluster)))

# tag::cluster_ping_n1ql[]
ping_result = cluster.ping(PingOptions(service_types=[ServiceType.Query]))
print(ping_result.as_json())
# end::cluster_ping_n1ql[]

# tag::cluster_diagnostics[]
diag_result = cluster.diagnostics()
print(diag_result.as_json())
# end::cluster_diagnostics[]

print("Cluster state: {}".format(diag_result.state))
Exemple #7
0
 def test_ping_report_id(self):
     if self.is_mock:
         raise SkipTest("Mock -- skip cluster.ping() tests")
     report_id = "11111"
     result = self.cluster.ping(PingOptions(report_id=report_id))
     self.assertIn(report_id, result.id)