def on_auth(self, f, connection, address): """ Checks for authentication of a connection. :param f: (:class:`~hazelcast.future.Future`), future that contains the result of authentication. :param connection: (:class:`~hazelcast.connection.Connection`), newly established connection. :param address: (:class:`~hazelcast.core.Address`), the adress of new connection. :return: Result of authentication. """ if f.is_success(): self.logger.info("Authenticated with %s", f.result(), extra=self._logger_extras) with self._new_connection_mutex: self.connections[connection.endpoint] = f.result() try: self._pending_connections.pop(address) except KeyError: pass for on_connection_opened, _ in self._connection_listeners: if on_connection_opened: on_connection_opened(f.result()) return f.result() else: self.logger.debug("Error opening %s", connection, extra=self._logger_extras) with self._new_connection_mutex: try: self._pending_connections.pop(address) except KeyError: pass six.reraise(f.exception().__class__, f.exception(), f.traceback())
def _on_auth(self, response, connection, address): if response.is_success(): response = client_authentication_codec.decode_response( response.result()) status = response["status"] if status == _AuthenticationStatus.AUTHENTICATED: return self._handle_successful_auth(response, connection, address) if status == _AuthenticationStatus.CREDENTIALS_FAILED: err = AuthenticationError( "Authentication failed. The configured cluster name on " "the client does not match the one configured in the cluster." ) elif status == _AuthenticationStatus.NOT_ALLOWED_IN_CLUSTER: err = ClientNotAllowedInClusterError( "Client is not allowed in the cluster") elif status == _AuthenticationStatus.SERIALIZATION_VERSION_MISMATCH: err = IllegalStateError( "Server serialization version does not match to client") else: err = AuthenticationError( "Authentication status code not supported. status: %s" % status) connection.close("Failed to authenticate connection", err) raise err else: e = response.exception() # This will set the exception for the pending connection future connection.close("Failed to authenticate connection", e) six.reraise(e.__class__, e, response.traceback())
def result(self): """Returns the result of the Future, which makes the call synchronous if the result has not been computed yet. Returns: Result of the Future. """ self._reactor_check() self._event.wait() if self._exception: six.reraise(self._exception.__class__, self._exception, self._traceback) if self._result == NONE_RESULT: return None else: return self._result
def assertTrueEventually(self, assertion, timeout=30): timeout_time = get_current_timestamp() + timeout exc_info = None while get_current_timestamp() < timeout_time: try: assertion() return except AssertionError: exc_info = sys.exc_info() time.sleep(0.1) if exc_info is None: raise Exception("Could not enter the assertion loop!") six.reraise(*exc_info)
def test_operation_from_multiple_threads(self): num_threads = 4 num_iterations = 5000 value_size = 1000 key_range = 50 timeout = 300 keys = list(range(0, key_range)) exceptions = [] value = "v" * value_size def put_get_remove(): for i in range(0, num_iterations): if i % 100 == 0: self.logger.info("op %i", i) try: key = choice(keys) self.map.lock(key) self.map.put(key, value) self.assertEqual(value, self.map.get(key)) self.assertEqual(value, self.map.remove(key)) self.map.unlock(key) except: self.logger.exception("Exception in thread") exceptions.append( (threading.currentThread().getName(), sys.exc_info())) threads = [ self.start_new_thread(put_get_remove) for _ in range(0, num_threads) ] for t in threads: t.join(timeout) if t.isAlive(): self.fail("thread %s did not finish in %s seconds" % (t.getName(), timeout)) if exceptions: name, exception = exceptions[0] self.logger.exception("Exception in thread %s", name) six.reraise(exception[0].__class__, exception[0], exception[2])
def handle_exception(e, traceback): if isinstance(e, MemoryError): # TODO six.print_("OUT OF MEMORY") six.reraise(MemoryError, e, traceback) elif isinstance(e, HazelcastSerializationError): six.reraise(HazelcastSerializationError, e, traceback) else: six.reraise(HazelcastSerializationError, HazelcastSerializationError(e.args[0]), traceback)
def result(self): six.reraise(self._exception.__class__, self._exception, self._traceback)