예제 #1
0
    def setUpClass(cls):
        # auto-discovery with unicast on the same host only works if all nodes are configured with the same port range
        transport_port_range = bind_range(range_size=cls.NUM_SERVERS)
        for i in range(cls.NUM_SERVERS):
            layer = CrateNode(
                crate_dir=crate_path(),
                version=(4, 0, 0),
                settings={
                    'cluster.name': cls.__class__.__name__,
                    'node.name': cls.node_name(i),
                    'psql.port': 0,
                    'transport.tcp.port': transport_port_range,
                },
                env={
                    'JAVA_HOME': os.environ.get('JAVA_HOME', ''),
                    'CRATE_HEAP_SIZE': '256M'
                }
            )
            layer.start()
            cls.HTTP_PORTS.append(layer.addresses.http.port)
            cls.CRATES.append(layer)

        dsn = cls.random_dns()
        num_nodes = 0

        # wait until all nodes joined the cluster
        with connect(dsn) as conn:
            c = conn.cursor()
            while num_nodes < len(cls.CRATES):
                c.execute("select * from sys.nodes")
                num_nodes = len(c.fetchall())
                time.sleep(5)
예제 #2
0
파일: test_reindex.py 프로젝트: rps-v/cr8
    def test_reindex(self):
        crate_v3 = CrateNode(crate_dir=get_crate('3.x.x'),
                             keep_data=True,
                             settings=self.crate_settings)
        self._to_stop.append(crate_v3)
        crate_v3.start()
        with connect(crate_v3.http_url) as conn:
            cur = conn.cursor()
            cur.execute("create table t (x int)")
            args = (
                (1, ),
                (2, ),
                (3, ),
            )
            cur.executemany("insert into t (x) values (?)", args)
        crate_v3.stop()
        self._to_stop.remove(crate_v3)

        crate_v4 = CrateNode(crate_dir=get_crate('4.0.3'),
                             keep_data=True,
                             settings=self.crate_settings)
        self._to_stop.append(crate_v4)
        crate_v4.start()
        reindex(crate_v4.http_url)
        with connect(crate_v4.http_url) as conn:
            cur = conn.cursor()
            cur.execute(
                "SELECT version FROM information_schema.tables WHERE table_name = 't'"
            )
            version, = cur.fetchone()
            self.assertEqual(version, {'upgraded': None, 'created': '4.0.3'})

            cur.execute('SELECT count(*) FROM t')
            cnt, = cur.fetchone()
            self.assertEqual(cnt, 3)
예제 #3
0
    def test_reindex(self):
        crate_v3 = CrateNode(crate_dir=get_crate('3.x.x'),
                             keep_data=True,
                             settings=self.crate_settings)
        self._to_stop.append(crate_v3)
        crate_v3.start()
        with client(crate_v3.http_url) as c:
            aio.run(c.execute, "create table t (x int)")
            args = (
                (1, ),
                (2, ),
                (3, ),
            )
            aio.run(c.execute_many, "insert into t (x) values (?)", args)
        crate_v3.stop()
        self._to_stop.remove(crate_v3)

        crate_v4 = CrateNode(crate_dir=get_crate('4.0.3'),
                             keep_data=True,
                             settings=self.crate_settings)
        self._to_stop.append(crate_v4)
        crate_v4.start()
        reindex(crate_v4.http_url)
        with client(crate_v4.http_url) as c:
            result = aio.run(
                c.execute,
                "SELECT version FROM information_schema.tables WHERE table_name = 't'"
            )
            version = result['rows'][0][0]
            self.assertEqual(version, {'upgraded': None, 'created': '4.0.3'})

            cnt = aio.run(c.execute, 'SELECT count(*) FROM t')['rows'][0][0]
            self.assertEqual(cnt, 3)
예제 #4
0
    def setUp(self):
        zone_file = '''
crate.internal.               600   IN   SOA   localhost localhost ( 2007120710 1d 2h 4w 1h )
crate.internal.               400   IN   NS    localhost
crate.internal.               600   IN   A     127.0.0.1'''

        transport_ports = [bind_port() for _ in range(self.num_nodes)]
        for port in transport_ports:
            zone_file += '''
_test._srv.crate.internal.    600   IN   SRV   1 10 {port} 127.0.0.1.'''.format(
                port=port)

        dns_port = bind_port()
        self.dns_server = DNSServer(ZoneResolver(zone_file), port=dns_port)
        self.dns_server.start_thread()

        self.nodes = nodes = []
        for i in range(self.num_nodes):
            settings = {
                'node.name': f'node-{i}',
                'cluster.name': 'crate-dns-discovery',
                'psql.port': 0,
                'transport.tcp.port': transport_ports[i],
                "discovery.seed_providers": "srv",
                "discovery.srv.query": "_test._srv.crate.internal.",
                "discovery.srv.resolver": "127.0.0.1:" + str(dns_port)
            }
            if i is 0:
                settings['cluster.initial_master_nodes'] = f'node-{i}'
            node = CrateNode(crate_dir=crate_path(),
                             version=(4, 0, 0),
                             settings=settings,
                             env={'CRATE_HEAP_SIZE': '256M'})
            node.start()
            nodes.append(node)
예제 #5
0
    def setUp(self):
        zone_file = '''
crate.internal.               600   IN   SOA   localhost localhost ( 2007120710 1d 2h 4w 1h )
crate.internal.               400   IN   NS    localhost
crate.internal.               600   IN   A     127.0.0.1'''

        transport_ports = [bind_port() for _ in range(self.num_nodes)]
        for port in transport_ports:
            zone_file += '''
_test._srv.crate.internal.    600   IN   SRV   1 10 {port} 127.0.0.1.'''.format(port=port)

        dns_port = bind_port()
        self.dns_server = DNSServer(ZoneResolver(zone_file), port=dns_port)
        self.dns_server.start_thread()

        self.nodes = nodes = []
        for i in range(self.num_nodes):
            settings = {
                         'node.name': f'node-{i}',
                         'cluster.name': 'crate-dns-discovery',
                         'psql.port': 0,
                         'transport.tcp.port': transport_ports[i],
                         "discovery.seed_providers": "srv",
                         "discovery.srv.query": "_test._srv.crate.internal.",
                         "discovery.srv.resolver": "127.0.0.1:" + str(dns_port)
                     }
            if i is 0:
                settings['cluster.initial_master_nodes'] = f'node-{i}'
            node = CrateNode(
                crate_dir=crate_path(),
                version=(4, 0, 0),
                settings=settings,
                env={
                    'CRATE_HEAP_SIZE': '256M'
                }
            )
            node.start()
            nodes.append(node)