Example #1
0
    def test_resolve_and_reconnect_on_node_down(self):

        self.connect(self.creds,
                     idle_heartbeat_interval=1,
                     idle_heartbeat_timeout=1,
                     reconnection_policy=ConstantReconnectionPolicy(120))

        self.assertEqual(len(self.hosts_up()), 3)
        CLOUD_PROXY_SERVER.stop_node(1)
        wait_until_not_raised(
            lambda: self.assertEqual(len(self.hosts_up()), 2), 0.02, 250)

        host = [h for h in self.cluster.metadata.all_hosts() if not h.is_up][0]
        with patch.object(SniEndPoint, "resolve",
                          wraps=host.endpoint.resolve) as mocked_resolve:
            CLOUD_PROXY_SERVER.start_node(1)
            wait_until_not_raised(
                lambda: self.assertEqual(len(self.hosts_up()), 3), 0.02, 250)
            mocked_resolve.assert_called_once()
Example #2
0
    def submit_request(self, query):
        opener = build_opener(HTTPHandler)
        data = json.dumps(query.fetch_json()).encode('utf8')

        request = Request("http://{}/{}{}".format(self.admin_addr, query.path,
                                                  query.fetch_url_params()),
                          data=data)
        request.get_method = lambda: query.method
        request.add_header("Content-Type", 'application/json')
        request.add_header("Content-Length", len(data))

        # wait that simulacron is ready and listening
        connection = wait_until_not_raised(lambda: opener.open(request), 1, 10)
        return connection.read().decode('utf-8')
def setup_module():
    use_singledc(start=False)
    ccm_cluster = get_cluster()
    ccm_cluster.stop()
    config_options = {'native_transport_port': 9046}
    ccm_cluster.set_configuration_options(config_options)
    # can't use wait_for_binary_proto cause ccm tries on port 9042
    ccm_cluster.start(wait_for_binary_proto=False)
    # wait until all nodes are up
    wait_until_not_raised(lambda: TestCluster(contact_points=['127.0.0.1'], port=9046).connect().shutdown(), 1, 20)
    wait_until_not_raised(lambda: TestCluster(contact_points=['127.0.0.2'], port=9046).connect().shutdown(), 1, 20)
    wait_until_not_raised(lambda: TestCluster(contact_points=['127.0.0.3'], port=9046).connect().shutdown(), 1, 20)
Example #4
0
    def __test_udt(self, schema, graphson, address_class,
                   address_with_tags_class, complex_address_class,
                   complex_address_with_owners_class):
        if schema is not CoreGraphSchema or DSE_VERSION < Version('6.8'):
            raise unittest.SkipTest(
                "Graph UDT is only supported with DSE 6.8+ and Core graphs.")

        ep = self.get_execution_profile(graphson)

        Address = address_class
        AddressWithTags = address_with_tags_class
        ComplexAddress = complex_address_class
        ComplexAddressWithOwners = complex_address_with_owners_class

        # setup udt
        self.session.execute_graph("""
                schema.type('address').property('address', Text).property('city', Text).property('state', Text).create();
                schema.type('addressTags').property('address', Text).property('city', Text).property('state', Text).
                    property('tags', setOf(Text)).create();
                schema.type('complexAddress').property('address', Text).property('address_tags', frozen(typeOf('addressTags'))).
                    property('city', Text).property('state', Text).property('props', mapOf(Text, Int)).create();
                schema.type('complexAddressWithOwners').property('address', Text).
                    property('address_tags', frozen(typeOf('addressTags'))).
                    property('city', Text).property('state', Text).property('props', mapOf(Text, Int)).
                    property('owners', frozen(listOf(tupleOf(Text, Int)))).create();
                """,
                                   execution_profile=ep)

        # wait max 10 seconds to get the UDT discovered.
        wait_until_not_raised(
            lambda: self.session.cluster.register_user_type(
                self.graph_name, 'address', Address), 1, 10)
        wait_until_not_raised(
            lambda: self.session.cluster.register_user_type(
                self.graph_name, 'addressTags', AddressWithTags), 1, 10)
        wait_until_not_raised(
            lambda: self.session.cluster.register_user_type(
                self.graph_name, 'complexAddress', ComplexAddress), 1, 10)
        wait_until_not_raised(
            lambda: self.session.cluster.register_user_type(
                self.graph_name, 'complexAddressWithOwners',
                ComplexAddressWithOwners), 1, 10)

        data = {
            "udt1":
            ["typeOf('address')",
             Address('1440 Rd Smith', 'Quebec', 'QC')],
            "udt2": [
                "tupleOf(typeOf('address'), Text)",
                (Address('1440 Rd Smith', 'Quebec', 'QC'), 'hello')
            ],
            "udt3": [
                "tupleOf(frozen(typeOf('address')), Text)",
                (Address('1440 Rd Smith', 'Quebec', 'QC'), 'hello')
            ],
            "udt4": [
                "tupleOf(tupleOf(Int, typeOf('address')), Text)",
                ((42, Address('1440 Rd Smith', 'Quebec', 'QC')), 'hello')
            ],
            "udt5": [
                "tupleOf(tupleOf(Int, typeOf('addressTags')), Text)",
                ((42,
                  AddressWithTags('1440 Rd Smith', 'Quebec', 'QC',
                                  {'t1', 't2'})), 'hello')
            ],
            "udt6": [
                "tupleOf(tupleOf(Int, typeOf('complexAddress')), Text)",
                ((42,
                  ComplexAddress(
                      '1440 Rd Smith',
                      AddressWithTags('1440 Rd Smith', 'Quebec', 'QC',
                                      {'t1', 't2'}), 'Quebec', 'QC', {
                                          'p1': 42,
                                          'p2': 33
                                      })), 'hello')
            ],
            "udt7": [
                "tupleOf(tupleOf(Int, frozen(typeOf('complexAddressWithOwners'))), Text)",
                ((42,
                  ComplexAddressWithOwners(
                      '1440 Rd Smith',
                      AddressWithTags('1440 CRd Smith', 'Quebec', 'QC',
                                      {'t1', 't2'}), 'Quebec', 'QC', {
                                          'p1': 42,
                                          'p2': 33
                                      }, [('Mike', 43),
                                          ('Gina', 39)])), 'hello')
            ]
        }

        g = self.fetch_traversal_source(graphson)
        for typ, value in six.itervalues(data):
            vertex_label = VertexLabel([typ])
            property_name = next(six.iterkeys(vertex_label.non_pk_properties))
            schema.create_vertex_label(self.session,
                                       vertex_label,
                                       execution_profile=ep)

            write_traversal = g.addV(str(vertex_label.label)).property('pkid', vertex_label.id). \
                property(property_name, value)
            self.execute_traversal(write_traversal, graphson)

            #vertex = list(schema.add_vertex(self.session, vertex_label, property_name, value, execution_profile=ep))[0]
            #vertex_properties = list(schema.get_vertex_properties(
            #    self.session, vertex, execution_profile=ep))

            read_traversal = g.V().hasLabel(str(
                vertex_label.label)).has(property_name).properties()
            vertex_properties = self.execute_traversal(read_traversal,
                                                       graphson)

            self.assertEqual(len(vertex_properties), 2)  # include pkid
            for vp in vertex_properties:
                if vp.label == 'pkid':
                    continue

                self.assertIsInstance(vp, (VertexProperty, TravVertexProperty))
                self.assertEqual(vp.label, property_name)
                self.assertEqual(vp.value, value)