/*
 * Copyright (c) 2008-2017, 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.
 */

package com.hazelcast.reliableidgen.impl;

import com.hazelcast.reliableidgen.ReliableIdGenerator;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.test.HazelcastParallelClassRunner;
import com.hazelcast.test.HazelcastTestSupport;
import com.hazelcast.test.TestHazelcastInstanceFactory;
import com.hazelcast.test.annotation.ParallelTest;
import com.hazelcast.test.annotation.QuickTest;
import com.hazelcast.util.function.Supplier;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;

@RunWith(HazelcastParallelClassRunner.class)
@Category({QuickTest.class, ParallelTest.class})
public class ReliableIdGenerator_MemberIntegrationTest extends HazelcastTestSupport {

    private TestHazelcastInstanceFactory factory;
    private HazelcastInstance[] instances;

    @Before
    public void before() {
        factory = createHazelcastInstanceFactory(1);
        instances = factory.newInstances();
    }

    @After
    public void after() {
        factory.shutdownAll();
    }

    @Test
    public void smokeTest() throws Exception {
        final ReliableIdGenerator generator = instances[0].getReliableIdGenerator("gen");
        ReliableIdConcurrencyTestUtil.concurrentlyGenerateIds(new Supplier<Long>() {
            @Override
            public Long get() {
                return generator.newId();
            }
        });
    }
}

@@ -688,86 +688,86 @@
 ast.
-reliableidgen.ReliableIdGenerator;%0Aimport com.hazelcast.core.HazelcastInstance
+core.HazelcastInstance;%0Aimport com.hazelcast.reliableidgen.ReliableIdGenerator
 ;%0Aim
@@ -1117,16 +1117,39 @@
 Before;%0A
+import org.junit.Rule;%0A
 import o
@@ -1237,20 +1237,215 @@
 t.ru
-nner.RunWith
+les.ExpectedException;%0Aimport org.junit.runner.RunWith;%0A%0Aimport static com.hazelcast.instance.BuildInfoProvider.HAZELCAST_INTERNAL_OVERRIDE_VERSION;%0Aimport static com.hazelcast.internal.cluster.Versions.V3_9
 ;%0A%0A@
@@ -1632,53 +1632,81 @@
     
-private TestHazelcastInstanceFactory factory;
+@Rule%0A    public ExpectedException exception = ExpectedException.none();%0A
 %0A   
@@ -1714,16 +1714,20 @@
 private 
+Test
 Hazelcas
@@ -1739,20 +1739,23 @@
 ance
-%5B%5D instances
+Factory factory
 ;%0A%0A 
@@ -1845,55 +1845,11 @@
 ory(
-1
 );%0A
-        instances = factory.newInstances();
 %0A   
@@ -1984,16 +1984,85 @@
 ption %7B%0A
+        HazelcastInstance instance = factory.newHazelcastInstance();%0A
         
@@ -2111,12 +2111,8 @@
 ance
-s%5B0%5D
 .get
@@ -2351,11 +2351,419 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void when_310MemberJoinsWith39Mode_reliableIdGeneratorDoesNotWork() %7B%0A        System.setProperty(HAZELCAST_INTERNAL_OVERRIDE_VERSION, V3_9.toString());%0A        HazelcastInstance instance = factory.newHazelcastInstance();%0A%0A        ReliableIdGenerator gen = instance.getReliableIdGenerator(%22gen%22);%0A        exception.expect(UnsupportedOperationException.class);%0A        gen.newId();%0A    %7D
 %0A%7D%0A

Add test for 3.9 cluster