<commit_before>/*
 * Copyright (c) 2008-2018, 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.spi.impl.operationservice.impl;

import com.hazelcast.config.Config;
import com.hazelcast.config.MapConfig;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.test.HazelcastSerialClassRunner;
import com.hazelcast.test.HazelcastTestSupport;
import com.hazelcast.test.TestHazelcastInstanceFactory;
import com.hazelcast.test.annotation.NightlyTest;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;

import java.util.Map;
import java.util.Random;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.fail;

/**
 * Verifies how well Hazelcast is able to deal with a cluster where members
 * are joining and leaving all the time, so partitions are moving.
 *
 * In this cluster, partitioned calls are made and therefor it happens
 * frequently that calls are sent to the wrong machine.
 */
@RunWith(HazelcastSerialClassRunner.class)
@Category(NightlyTest.class)
public class RepartitioningStressTest extends HazelcastTestSupport {

    private static final int INITIAL_MEMBER_COUNT = 5;
    private static final int THREAD_COUNT = 10;
    private static final int DURATION_SECONDS = 120;

    private BlockingQueue<HazelcastInstance> queue = new LinkedBlockingQueue<HazelcastInstance>();

    private TestHazelcastInstanceFactory instanceFactory;
    private Config config;
    private HazelcastInstance hz;

    private RestartThread restartThread;

    @Before
    public void setUp() {
        Hazelcast.shutdownAll();

        instanceFactory = createHazelcastInstanceFactory(10000);
        config = new Config();
        config.getGroupConfig().setName(generateRandomString(10));
        MapConfig mapConfig = new MapConfig("map");
        //mapConfig.setBackupCount(0);
        config.addMapConfig(mapConfig);
        hz = createHazelcastInstance();

        for (int i = 0; i < INITIAL_MEMBER_COUNT; i++) {
            queue.add(createHazelcastInstance());
        }

        restartThread = new RestartThread();
    }

    @After
    public void tearDown() throws InterruptedException {
        restartThread.stopAndJoin();
        Hazelcast.shutdownAll();
    }

    @Override
    public HazelcastInstance createHazelcastInstance() {
        return instanceFactory.newHazelcastInstance(config);
    }

    @Test
    @Ignore(value = "https://github.com/hazelcast/hazelcast/issues/3683")
    public void callWithBackups() throws Exception {
        int itemCount = 10000;
        ConcurrentMap<Integer, Integer> map = hz.getMap("map");

        for (int i = 0; i < itemCount; i++) {
            map.put(i, 0);
        }

        restartThread.start();
<commit_msg>[#3066] Re-enabling RepartitioningStreeTest.callWithBackups (#12318)<commit_after>/*
 * Copyright (c) 2008-2018, 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.spi.impl.operationservice.impl;

import com.hazelcast.config.Config;
import com.hazelcast.config.MapConfig;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.test.HazelcastSerialClassRunner;
import com.hazelcast.test.HazelcastTestSupport;
import com.hazelcast.test.TestHazelcastInstanceFactory;
import com.hazelcast.test.annotation.NightlyTest;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;

import java.util.Map;
import java.util.Random;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.fail;

/**
 * Verifies how well Hazelcast is able to deal with a cluster where members
 * are joining and leaving all the time, so partitions are moving.
 *
 * In this cluster, partitioned calls are made and therefor it happens
 * frequently that calls are sent to the wrong machine.
 */
@RunWith(HazelcastSerialClassRunner.class)
@Category(NightlyTest.class)
public class RepartitioningStressTest extends HazelcastTestSupport {

    private static final int INITIAL_MEMBER_COUNT = 5;
    private static final int THREAD_COUNT = 10;
    private static final int DURATION_SECONDS = 120;

    private BlockingQueue<HazelcastInstance> queue = new LinkedBlockingQueue<HazelcastInstance>();

    private TestHazelcastInstanceFactory instanceFactory;
    private Config config;
    private HazelcastInstance hz;

    private RestartThread restartThread;

    @Before
    public void setUp() {
        Hazelcast.shutdownAll();

        instanceFactory = createHazelcastInstanceFactory(10000);
        config = new Config();
        config.getGroupConfig().setName(generateRandomString(10));
        MapConfig mapConfig = new MapConfig("map");
        //mapConfig.setBackupCount(0);
        config.addMapConfig(mapConfig);
        hz = createHazelcastInstance();

        for (int i = 0; i < INITIAL_MEMBER_COUNT; i++) {
            queue.add(createHazelcastInstance());
        }

        restartThread = new RestartThread();
    }

    @After
    public void tearDown() throws InterruptedException {
        restartThread.stopAndJoin();
        Hazelcast.shutdownAll();
    }

    @Override
    public HazelcastInstance createHazelcastInstance() {
        return instanceFactory.newHazelcastInstance(config);
    }

    @Test
    public void callWithBackups() throws Exception {
        int itemCount = 10000;
        ConcurrentMap<Integer, Integer> map = hz.getMap("map");

        for (int i = 0; i < itemCount; i++) {
            map.put(i, 0);
        }

        restartThread.start();

{'fraction_non_alphanumeric': 0.08777945412151968, 'fraction_numerical': 0.011109587162254835, 'mean_word_length': 3.8873994638069704, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 9, 'https://': 1, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4235599', 'n_tokens_mistral': 2166, 'n_tokens_neox': 2079, 'n_words': 587}