def setUpClass(cls):
     cls.rc = cls.create_rc()
     cls.is_v5_or_newer_server = compare_server_version_with_rc(
         cls.rc, "5.0") >= 0
     cls.is_v5_or_newer_client = compare_client_version("5.0") >= 0
     # enable Jet if the server is 5.0+
     cluster_config = SERVER_CONFIG % (JET_ENABLED_CONFIG
                                       if cls.is_v5_or_newer_server else "")
     cls.cluster = cls.create_cluster(cls.rc, cluster_config)
     cls.member = cls.cluster.start_member()
     cls.client = HazelcastClient(cluster_name=cls.cluster.id,
                                  portable_factories={666: {
                                      6: Student
                                  }})
 def configure_client(cls, config):
     config["cluster_name"] = cls.cluster.id
     if not compare_client_version("4.1") < 0:
         # Add these config elements only to the 4.1+ clients
         # since the older versions do not know anything
         # about them.
         config["reliable_topics"] = {
             "discard": {
                 "overload_policy": TopicOverloadPolicy.DISCARD_NEWEST,
             },
             "overwrite": {
                 "overload_policy": TopicOverloadPolicy.DISCARD_OLDEST,
             },
             "block": {
                 "overload_policy": TopicOverloadPolicy.BLOCK,
             },
             "error": {
                 "overload_policy": TopicOverloadPolicy.ERROR,
             },
         }
     return config
    pass

from tests.base import SingleMemberTestCase
from tests.util import (
    compare_client_version,
    random_string,
    event_collector,
    get_current_timestamp,
    skip_if_client_version_older_than,
)

CAPACITY = 10


@unittest.skipIf(
    compare_client_version("4.1") < 0,
    "Tests the features added in 4.1 version of the client")
class ReliableTopicTest(SingleMemberTestCase):
    @classmethod
    def configure_cluster(cls):
        path = os.path.abspath(__file__)
        dir_path = os.path.dirname(path)
        with open(os.path.join(dir_path, "hazelcast_topic.xml")) as f:
            return f.read()

    @classmethod
    def configure_client(cls, config):
        config["cluster_name"] = cls.cluster.id
        if not compare_client_version("4.1") < 0:
            # Add these config elements only to the 4.1+ clients
            # since the older versions do not know anything
        <member-server-socket-endpoint-config>
            <port>%s</port>
        </member-server-socket-endpoint-config>
        <client-server-socket-endpoint-config>
            <port>%s</port>
        </client-server-socket-endpoint-config>
    </advanced-network>
</hazelcast>
""" % (
    _SERVER_PORT,
    _CLIENT_PORT,
)


@unittest.skipIf(
    compare_client_version("5.0") < 0,
    "Tests the features added in 5.0 version of the client")
class AdvancedNetworkConfigTest(SingleMemberTestCase):
    @classmethod
    def configure_cluster(cls):
        return _SERVER_WITH_CLIENT_ENDPOINT

    @classmethod
    def configure_client(cls, config):
        config["cluster_members"] = ["localhost:%s" % _CLIENT_PORT]
        config["cluster_name"] = cls.cluster.id
        return config

    def test_member_list(self):
        members = self.client.cluster_service.get_members()
        self.assertEqual(1, len(members))
    def get_labels_from_member(self, client_uuid):
        script = """
        var clients = instance_0.getClientService().getConnectedClients().toArray();
        for (i=0; i < clients.length; i++) {
            var client = clients[i];
            if ("%s".equals(client.getUuid().toString())) {
                result = client.getLabels().iterator().next();
                break;
            }
        }""" % str(client_uuid)
        return self.rc.executeOnController(self.cluster.id, script,
                                           Lang.JAVASCRIPT).result


@unittest.skipIf(
    compare_client_version("4.2.2") < 0 or compare_client_version("5.0") == 0,
    "Tests the features added in 5.1 version of the client, "
    "which are backported into 4.2.2 and 5.0.1",
)
class ClientTcpMetricsTest(SingleMemberTestCase):
    @classmethod
    def configure_client(cls, config):
        config["cluster_name"] = cls.cluster.id
        return config

    def test_bytes_received(self):
        reactor = self.client._reactor

        bytes_received = reactor.bytes_received
        self.assertGreater(bytes_received, 0)
    pass

from tests.base import SingleMemberTestCase
from tests.util import (
    compare_client_version,
    random_string,
    event_collector,
    get_current_timestamp,
    skip_if_client_version_older_than,
)

CAPACITY = 10


@unittest.skipIf(
    compare_client_version("4.1") < 0, "Tests the features added in 4.1 version of the client"
)
class ReliableTopicTest(SingleMemberTestCase):
    @classmethod
    def configure_cluster(cls):
        path = os.path.abspath(__file__)
        dir_path = os.path.dirname(path)
        with open(os.path.join(dir_path, "hazelcast_topic.xml")) as f:
            return f.read()

    @classmethod
    def configure_client(cls, config):
        config["cluster_name"] = cls.cluster.id
        if not compare_client_version("4.1") < 0:
            # Add these config elements only to the 4.1+ clients
            # since the older versions do not know anything