Beispiel #1
0
 def setUp(self):
     self._backend = new_backend()
     self._server = StubServer(9001)
     self._driverName = get_driver_name()
     auth = AuthorizationToken()
     uri = "bolt://%s" % self._server.address
     self._driver = Driver(self._backend, uri,
                           AuthorizationToken(scheme="basic"))
Beispiel #2
0
    def test_read_twice(self):
        self._server.start(
            os.path.join(scripts_path, "retry_read_twice.script"))

        num_retries = 0

        def retry_twice(tx):
            nonlocal num_retries
            num_retries = num_retries + 1
            result = tx.run("RETURN 1")
            record = result.next()
            return record.values[0]

        auth = AuthorizationToken(scheme="basic",
                                  principal="neo4j",
                                  credentials="pass")
        driver = Driver(self._backend, "bolt://%s" % self._server.address,
                        auth)
        session = driver.session("r")
        x = session.readTransaction(retry_twice)
        self.assertIsInstance(x, types.CypherInt)
        self.assertEqual(x.value, 1)
        self.assertEqual(num_retries, 2)

        session.close()
        driver.close()
        self._server.done()
Beispiel #3
0
 def createDriverAndSession(self):
     auth_token = AuthorizationToken(
         scheme="basic",
         principal=os.environ.get(env_neo4j_user, "neo4j"),
         credentials=os.environ.get(env_neo4j_pass, "pass"))
     self._driver = Driver(self._backend, self._scheme, auth_token)
     self._session = self._driver.session("r")
 def testSuccessOnProvideRealmWithBasicToken(self):
     auth_token = AuthorizationToken(
         scheme="basic",
         realm="native",
         principal=os.environ.get(env_neo4j_user, "neo4j"),
         credentials=os.environ.get(env_neo4j_pass, "pass"))
     self.verifyConnectivity(auth_token)
Beispiel #5
0
    def test_disconnect_on_commit(self):
        # Should NOT retry when connection is lost on unconfirmed commit.
        # The rule could be relaxed on read transactions therefore we test on writeTransaction.
        # An error should be raised to indicate the failure
        if not self._driverName in ["go"]:
            self.skipTest(
                "Backend missing support for SessionWriteTransaction")
        self._server.start(script=script_commit_disconnect)
        num_retries = 0

        def once(tx):
            nonlocal num_retries
            num_retries = num_retries + 1
            result = tx.run("RETURN 1")
            record = result.next()

        auth = AuthorizationToken(scheme="basic")
        driver = Driver(self._backend, "bolt://%s" % self._server.address,
                        auth)
        session = driver.session("w")

        with self.assertRaises(types.DriverError) as e:  # Check further...
            session.writeTransaction(once)

        self.assertEqual(num_retries, 1)
        session.close()
        driver.close()
        self._server.done()
Beispiel #6
0
    def test_read(self):
        if self._driver in ["javascript"]:
            self.skipTest(
                "Transactional functions not implemented in testkit backend")

        script = "retry_read.script"
        if self._driver in ["go"]:
            # Until Go is updated to use PULL with n
            script = "retry_read_v3.script"
        self._server.start(os.path.join(scripts_path, script))

        num_retries = 0

        def retry_once(tx):
            nonlocal num_retries
            num_retries = num_retries + 1
            result = tx.run("RETURN 1")
            record = result.next()
            return record.values[0]

        auth = AuthorizationToken(scheme="basic",
                                  principal="neo4j",
                                  credentials="pass")
        driver = Driver(self._backend, "bolt://%s" % self._server.address,
                        auth)
        session = driver.session("r")
        x = session.readTransaction(retry_once)
        self.assertIsInstance(x, types.CypherInt)
        self.assertEqual(x.value, 1)
        self.assertEqual(num_retries, 1)

        session.close()
        driver.close()
        self._server.done()
Beispiel #7
0
 def _run(self, n, script, end, expectedSequence, expectedError=False):
     uri = "bolt://%s" % self._server.address
     driver = Driver(self._backend, uri, AuthorizationToken(scheme="basic"))
     self._server.start(script=script,
                        vars={
                            "#END#": end,
                            "#VERSION#": "4"
                        })
     session = driver.session("w", fetchSize=n)
     result = session.run("RETURN 1 AS n")
     gotError = False
     sequence = []
     while True:
         try:
             next = result.next()
         except Exception as e:
             gotError = True
             break
         if isinstance(next, types.NullRecord):
             break
         sequence.append(next.values[0].value)
     driver.close()
     self._server.done()
     self.assertEqual(expectedSequence, sequence)
     self.assertEqual(expectedError, gotError)
Beispiel #8
0
    def test_nested(self):
        if get_driver_name() not in ['go', 'dotnet']:
            self.skipTest(
                "Need support for specifying session fetch size in testkit backend"
            )
        uri = "bolt://%s" % self._server.address
        driver = Driver(self._backend, uri, AuthorizationToken(scheme="basic"))
        self._server.start(script=TxRun.script_nested_n,
                           vars={"#VERSION#": "4"})
        session = driver.session("w", fetchSize=1)
        tx = session.beginTransaction()
        res1 = tx.run("CYPHER")
        seq = []
        seqs = []
        while True:
            rec1 = res1.next()
            if isinstance(rec1, types.NullRecord):
                break
            seq.append(rec1.values[0].value)
            seq2 = []
            res2 = tx.run("CYPHER")
            while True:
                rec2 = res2.next()
                if isinstance(rec2, types.NullRecord):
                    break
                seq2.append(rec2.values[0].value)
            seqs.append(seq2)

        tx.commit()
        driver.close()
        self._server.done()
        self.assertEqual(["1_1", "1_2"], seq)
        self.assertEqual([["2_1", "2_2"], ["3_1"]], seqs)
 def testErrorOnIncorrectCredentials(self):
     auth_token = AuthorizationToken(scheme="basic",
                                     principal="fake",
                                     credentials="fake")
     with self.assertRaises(
             types.DriverError
     ) as e:  # TODO: Expand this to check errorType is AuthenticationError
         self.verifyConnectivity(auth_token)
Beispiel #10
0
 def setUp(self):
     self._backend = new_backend()
     self._server = StubServer(9001)
     self._driverName = get_driver_name()
     auth = AuthorizationToken(scheme="basic", principal="neo4j", credentials="pass")
     uri = "bolt://%s" % self._server.address
     self._driver = Driver(self._backend, uri, auth)
     self._session = self._driver.session("w")
Beispiel #11
0
 def setUp(self):
     self._backend = new_backend()
     self._routingServer = StubServer(9001)
     self._readServer = StubServer(9002)
     self._writeServer = StubServer(9003)
     self._uri = "neo4j://%s?region=china&policy=my_policy" % self._routingServer.address
     self._auth = AuthorizationToken(scheme="basic",
                                     principal="p",
                                     credentials="c")
     self._userAgent = "007"
Beispiel #12
0
def try_connect(backend, server, scheme, host):
    url = "%s://%s:%d" % (scheme, host, 6666)
    # Doesn't really matter
    auth = AuthorizationToken(scheme="basic",
                              principal="neo4j",
                              credentials="pass")
    driver = Driver(backend, url, auth)
    session = driver.session("r")
    try:
        result = session.run("RETURN 1 as n")
    except:
        pass
    session.close()
    driver.close()
    return server.connected()
Beispiel #13
0
    def test_session_run_read(self):
        if get_driver_name() not in ['go', 'dotnet']:
            self.skipTest(
                "Session with named database not implemented in backend")

        # Driver is configured to talk to "routing" stub server
        uri = "bolt://%s" % self._server.address
        self._server.start(script=self.script(), vars=self.get_vars())
        driver = Driver(self._backend,
                        uri,
                        AuthorizationToken(scheme="basic",
                                           principal="p",
                                           credentials="c"),
                        userAgent="007")
        session = driver.session('r', database="adb")
        session.run("RETURN 1 as n")
        session.close()
        driver.close()
        self._server.done()
Beispiel #14
0
    def test_read_twice(self):
        # We could probably use AUTO RESET in the script but this makes the diffs more
        # obvious.
        vars = {
            "$extra_reset_1": "",
            "$extra_reset_2": "",
        }
        if self._driverName not in ["go"]:
            vars["$extra_reset_2"] = "C: RESET\nS: SUCCESS {}"
        if self._driverName in ["java", "javascript"]:
            vars["$extra_reset_1"] = "C: RESET\nS: SUCCESS {}"

        self._server.start(script=script_retry, vars=vars)
        num_retries = 0

        def twice(tx):
            nonlocal num_retries
            num_retries = num_retries + 1
            result = tx.run("RETURN 1")
            record = result.next()
            return record.values[0]

        auth = AuthorizationToken(scheme="basic",
                                  principal="neo4j",
                                  credentials="pass")
        driver = Driver(self._backend, "bolt://%s" % self._server.address,
                        auth)
        session = driver.session("r")
        x = session.readTransaction(twice)
        self.assertIsInstance(x, types.CypherInt)
        self.assertEqual(x.value, 1)
        self.assertEqual(num_retries, 2)

        session.close()
        driver.close()
        self._server.done()
Beispiel #15
0
def get_authorization():
    """ Returns default authorization for tests that do not test this aspect
    """
    user = os.environ.get(env_neo4j_user, 'neo4j')
    passw = os.environ.get(env_neo4j_pass, 'pass')
    return AuthorizationToken(scheme="basic", principal=user, credentials=passw)