@Test
  public void testNodeFilter_from_xml() throws Exception {
    String xmlFileName = "hazelcast-client-discovery-spi-test.xml";
    InputStream xmlResource =
        ClientDiscoverySpiTest.class.getClassLoader().getResourceAsStream(xmlFileName);
    ClientConfig clientConfig = new XmlClientConfigBuilder(xmlResource).build();

    ClientNetworkConfig networkConfig = clientConfig.getNetworkConfig();

    DiscoveryStrategiesConfig discoveryStrategiesConfig =
        networkConfig.getDiscoveryStrategiesConfig();
    assertNotNull(discoveryStrategiesConfig);
    assertNotNull(discoveryStrategiesConfig.getNodeFilterClass());

    DiscoveryServiceProvider provider = new DefaultDiscoveryServiceProvider();
    DiscoveryService discoveryService =
        provider.newDiscoveryService(
            DiscoveryMode.Client,
            discoveryStrategiesConfig,
            ClientDiscoverySpiTest.class.getClassLoader());

    discoveryService.start();
    discoveryService.discoverNodes();
    discoveryService.destroy();

    Field nodeFilterField = DefaultDiscoveryService.class.getDeclaredField("nodeFilter");
    nodeFilterField.setAccessible(true);

    TestNodeFilter nodeFilter = (TestNodeFilter) nodeFilterField.get(discoveryService);

    assertEquals(4, nodeFilter.getNodes().size());
  }
  @Test
  public void testParsing() throws Exception {
    String xmlFileName = "hazelcast-client-discovery-spi-test.xml";
    InputStream xmlResource =
        ClientDiscoverySpiTest.class.getClassLoader().getResourceAsStream(xmlFileName);
    ClientConfig clientConfig = new XmlClientConfigBuilder(xmlResource).build();

    ClientNetworkConfig networkConfig = clientConfig.getNetworkConfig();

    AwsConfig awsConfig = networkConfig.getAwsConfig();
    assertNull(awsConfig);

    DiscoveryStrategiesConfig discoveryStrategiesConfig =
        networkConfig.getDiscoveryStrategiesConfig();
    assertTrue(discoveryStrategiesConfig.isEnabled());

    assertEquals(1, discoveryStrategiesConfig.getDiscoveryStrategyConfigs().size());

    DiscoveryStrategyConfig providerConfig =
        discoveryStrategiesConfig.getDiscoveryStrategyConfigs().iterator().next();

    assertEquals(3, providerConfig.getProperties().size());
    assertEquals("foo", providerConfig.getProperties().get("key-string"));
    assertEquals("123", providerConfig.getProperties().get("key-int"));
    assertEquals("true", providerConfig.getProperties().get("key-boolean"));
  }
示例#3
0
  private DiscoveryService createDiscoveryService(Config config) {
    JoinConfig joinConfig = config.getNetworkConfig().getJoin();
    DiscoveryStrategiesConfig providersConfig =
        joinConfig.getDiscoveryStrategiesConfig().getAsReadOnly();

    DiscoveryServiceProvider factory = providersConfig.getDiscoveryServiceProvider();
    if (factory == null) {
      factory = new DefaultDiscoveryServiceProvider();
    }
    return factory.newDiscoveryService(
        DiscoveryMode.Member, providersConfig, config.getClassLoader());
  }