Beispiel #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)
Beispiel #2
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)
Beispiel #3
0
JMX_PORT = bind_port()
JMX_OPTS = '''
     -Dcom.sun.management.jmxremote
     -Dcom.sun.management.jmxremote.port={}
     -Dcom.sun.management.jmxremote.ssl=false
     -Dcom.sun.management.jmxremote.authenticate=false
     -Dio.netty.leakDetection.level=paranoid
'''

env = os.environ.copy()
env['CRATE_JAVA_OPTS'] = JMX_OPTS.format(JMX_PORT)
env['CRATE_HEAP_SIZE'] = '256M'
enterprise_crate = CrateNode(crate_dir=crate_path(),
                             settings={
                                 'transport.tcp.port': 0,
                                 'psql.port': 0,
                                 'node.name': 'crate-enterprise',
                             },
                             env=env,
                             version=(4, 0, 0))


class JmxClient:

    SJK_JAR_URL = "https://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&g=org.gridkit.jvmtool&a=sjk&v=LATEST"

    CACHE_DIR = os.environ.get(
        'XDG_CACHE_HOME',
        os.path.join(os.path.expanduser('~'), '.cache', 'crate-tests'))

    def __init__(self, jmx_port):
        self.jmx_port = jmx_port
Beispiel #4
0
import os
import doctest
import subprocess
import functools
from cr8.run_crate import CrateNode, get_crate
from crate.client import connect

crate_dir = get_crate('latest-nightly')
node = CrateNode(crate_dir=crate_dir,
                 settings={
                     'cluster.name': 'cr8-tests',
                     'http.port': '44200-44250',
                     'bootstrap.system_call_filter': False
                 })


def setup(*args):
    with connect(node.http_url) as conn:
        c = conn.cursor()
        c.execute('create table x.demo (id int, name string, country string) \
                  with (number_of_replicas = 0)')
        c.execute('create blob table blobtable with (number_of_replicas = 0)')


def teardown(*args):
    try:
        with connect(node.http_url) as conn:
            c = conn.cursor()
            c.execute('drop table x.demo')
            c.execute('drop blob table blobtable')
    finally:
Beispiel #5
0
import os
import doctest
import subprocess
import functools
from cr8.run_crate import CrateNode, get_crate
from crate.client import connect


crate_dir = get_crate('latest-nightly')
node = CrateNode(
    crate_dir=crate_dir,
    settings={
        'cluster.name': 'cr8-tests',
        'http.port': '44200-44250',
    })


def setup(*args):
    with connect(node.http_url) as conn:
        c = conn.cursor()
        c.execute('create table x.demo (id int, name string, country string) \
                  with (number_of_replicas = 0)')
        c.execute('create blob table blobtable with (number_of_replicas = 0)')


def teardown(*args):
    try:
        with connect(node.http_url) as conn:
            c = conn.cursor()
            c.execute('drop table x.demo')
            c.execute('drop blob table blobtable')
Beispiel #6
0
import shutil
import tempfile
import threading
import unittest
import socket
from pathlib import Path
from crate.client import connect
from cr8.run_crate import CrateNode, wait_until
from subprocess import Popen, PIPE, DEVNULL
from testutils.paths import crate_path
from urllib.request import urlretrieve

crate_node = CrateNode(crate_dir=crate_path(),
                       settings={
                           'transport.tcp.port': 0,
                           'psql.port': 0,
                       },
                       env={'CRATE_HEAP_SIZE': '256M'},
                       version=(4, 0, 0))


def _is_up(host: str, port: int) -> bool:
    try:
        conn = socket.create_connection((host, port))
        conn.close()
        return True
    except (socket.gaierror, ConnectionRefusedError):
        return False


class MinioServer:
Beispiel #7
0
crate = CrateNode(
    crate_dir=crate_path(),
    settings={
        'ssl.psql.enabled':
        True,
        # keystore and certs were generated using the ./devs/tools/create_certs.py script
        'ssl.keystore_filepath':
        join(project_root, 'blackbox', 'certs', 'node1.jks'),
        'ssl.keystore_password':
        '******',
        'ssl.keystore_key_password':
        '******',
        'transport.tcp.port':
        0,
        'node.name':
        'crate-ssl-test',
        'discovery.type':
        'single-node',
        'auth.host_based.enabled':
        True,
        'auth.host_based.config.0.user':
        '******',
        'auth.host_based.config.0.method':
        'trust',
        'auth.host_based.config.1.user':
        '******',
        'auth.host_based.config.1.method':
        'cert',
        'auth.host_based.config.1.ssl':
        'on',
    },
    env=env,
    version=(4, 2, 0))
from test_jmx import JmxClient

JMX_PORT = bind_port()
JMX_OPTS = '''
     -Dcom.sun.management.jmxremote
     -Dcom.sun.management.jmxremote.port={}
     -Dcom.sun.management.jmxremote.ssl=false
     -Dcom.sun.management.jmxremote.authenticate=false
'''

env = os.environ.copy()
env['CRATE_JAVA_OPTS'] = JMX_OPTS.format(JMX_PORT)
crate_layer = CrateNode(crate_dir=crate_path(),
                        version=(4, 0, 0),
                        settings={
                            'transport.tcp.port': 0,
                            'node.name': 'crate-ce',
                        },
                        env=env)


class CeHasNoEnterpriseModulesITest(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        crate_layer.start()

    @classmethod
    def tearDownClass(cls):
        crate_layer.stop()

    def test_enterprise_jmx_not_available(self):