Skip to content

Commit

Permalink
Merge pull request #8614 from bilalyasar/bilalyasar-mp-fix
Browse files Browse the repository at this point in the history
fixed multicast plugin bug and added test
  • Loading branch information
Donnerbart committed Jul 28, 2016
2 parents 2eaf800 + 1b2045b commit bd4cfd1
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 5 deletions.
Expand Up @@ -36,6 +36,8 @@
import java.util.HashMap;
import java.util.Map;

import static com.hazelcast.util.ExceptionUtil.rethrow;

/**
* The multicast {@link com.hazelcast.spi.discovery.DiscoveryStrategy}.
*/
Expand Down Expand Up @@ -82,6 +84,7 @@ private void initializeMulticastSocket() {
}
} catch (Exception e) {
logger.finest(e.getMessage());
rethrow(e);
}
}

Expand Down
Expand Up @@ -22,13 +22,26 @@
import com.hazelcast.spi.discovery.DiscoveryStrategy;
import com.hazelcast.spi.discovery.DiscoveryStrategyFactory;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
* TODO:
* Factory class which returns {@link MulticastDiscoveryStrategy} to Discovery SPI
*/
public class MulticastDiscoveryStrategyFactory implements DiscoveryStrategyFactory {

private static final Collection<PropertyDefinition> PROPERTY_DEFINITIONS;

static {
List<PropertyDefinition> propertyDefinitions = new ArrayList<PropertyDefinition>();
propertyDefinitions.add(MulticastProperties.GROUP);
propertyDefinitions.add(MulticastProperties.PORT);
PROPERTY_DEFINITIONS = Collections.unmodifiableCollection(propertyDefinitions);
}

@Override
public Class<? extends DiscoveryStrategy> getDiscoveryStrategyType() {
return MulticastDiscoveryStrategy.class;
Expand All @@ -41,6 +54,6 @@ public DiscoveryStrategy newDiscoveryStrategy(DiscoveryNode discoveryNode, ILogg

@Override
public Collection<PropertyDefinition> getConfigurationProperties() {
return null;
return PROPERTY_DEFINITIONS;
}
}
Expand Up @@ -18,6 +18,7 @@

import com.hazelcast.config.Config;
import com.hazelcast.config.XmlConfigBuilder;
import com.hazelcast.config.properties.ValidationException;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.test.HazelcastSerialClassRunner;
import com.hazelcast.test.HazelcastTestSupport;
Expand All @@ -26,6 +27,7 @@
import com.hazelcast.test.annotation.QuickTest;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
Expand All @@ -37,7 +39,7 @@
public class MemberToMemberDiscoveryTest extends HazelcastTestSupport {

private Config config;
private TestHazelcastInstanceFactory factory;
private TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);

@Before
public void setUp() {
Expand All @@ -47,7 +49,6 @@ public void setUp() {

System.setProperty(TestEnvironment.HAZELCAST_TEST_USE_NETWORK, "true");
System.setProperty("java.net.preferIPv4Stack", "true");
factory = createHazelcastInstanceFactory(2);
}

@After
Expand All @@ -58,7 +59,19 @@ public void tearDown() {
@Test
public void formClusterWithTwoMembersTest() throws InterruptedException {
HazelcastInstance[] instances = factory.newInstances(config);

assertClusterSizeEventually(2, instances[0]);
}

@Test(expected = ValidationException.class)
public void invalidPortPropertyTest() throws InterruptedException {
String xmlFileName = "hazelcast-multicast-plugin-invalid-port.xml";
InputStream xmlResource = MulticastDiscoveryStrategy.class.getClassLoader().getResourceAsStream(xmlFileName);
config = new XmlConfigBuilder(xmlResource).build();
factory.newInstances(config);
}

@After
public void shutdown() {
factory.shutdownAll();
}
}
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2008-2016, Hazelcast, Inc. All Rights Reserved.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<hazelcast xsi:schemaLocation="http://www.hazelcast.com/schema/config hazelcast-config-3.6.xsd"
xmlns="http://www.hazelcast.com/schema/config"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<properties>
<property name="hazelcast.discovery.enabled">true</property>
</properties>

<network>
<port>6001</port>
<join>
<multicast enabled="false"/>
<tcp-ip enabled="false" />
<aws enabled="false"/>
<discovery-strategies>
<discovery-strategy enabled="true" class="com.hazelcast.spi.discovery.multicast.MulticastDiscoveryStrategy">
<properties>
<property name="port">-1</property>
</properties>
</discovery-strategy>
</discovery-strategies>
</join>
</network>

</hazelcast>

0 comments on commit bd4cfd1

Please sign in to comment.