<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.topic.impl.reliable;

import com.hazelcast.config.Config;
import com.hazelcast.config.RingbufferConfig;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.Member;
import com.hazelcast.instance.TestUtil;
import com.hazelcast.ringbuffer.Ringbuffer;
import com.hazelcast.test.AssertTask;
import com.hazelcast.test.HazelcastParallelClassRunner;
import com.hazelcast.test.HazelcastTestSupport;
import com.hazelcast.test.annotation.ParallelTest;
import com.hazelcast.test.annotation.QuickTest;
import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;

import static com.hazelcast.ringbuffer.impl.RingbufferService.TOPIC_RB_PREFIX;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

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

    private static final String RELIABLE_TOPIC_NAME = "foo";
    private ReliableTopicProxy<String> topic;
    private Ringbuffer<ReliableTopicMessage> ringbuffer;
    private HazelcastInstance topicOwnerInstance;
    private HazelcastInstance topicBackupInstance;

    @Before
    public void setup() {
        Config config = smallInstanceConfig().addRingBufferConfig(
                new RingbufferConfig(RELIABLE_TOPIC_NAME)
                        .setCapacity(100)
                        .setTimeToLiveSeconds(0)
                        .setBackupCount(0)
                        .setAsyncBackupCount(0));
        final HazelcastInstance[] instances = createHazelcastInstanceFactory(2).newInstances(config);

        for (HazelcastInstance instance : instances) {
            final Member owner = instance.getPartitionService().getPartition(TOPIC_RB_PREFIX + RELIABLE_TOPIC_NAME).getOwner();
            final Member localMember = instance.getCluster().getLocalMember();
            if (localMember.equals(owner)) {
                topicOwnerInstance = instance;
            } else {
                topicBackupInstance = instance;
            }
        }

        topic = (ReliableTopicProxy<String>) topicBackupInstance.<String>getReliableTopic(RELIABLE_TOPIC_NAME);
        ringbuffer = topic.ringbuffer;<commit_msg>Fixes uninitialized partition in LossToleranceTest<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.topic.impl.reliable;

import com.hazelcast.config.Config;
import com.hazelcast.config.RingbufferConfig;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.Member;
import com.hazelcast.instance.TestUtil;
import com.hazelcast.ringbuffer.Ringbuffer;
import com.hazelcast.test.AssertTask;
import com.hazelcast.test.HazelcastParallelClassRunner;
import com.hazelcast.test.HazelcastTestSupport;
import com.hazelcast.test.annotation.ParallelTest;
import com.hazelcast.test.annotation.QuickTest;
import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;

import static com.hazelcast.ringbuffer.impl.RingbufferService.TOPIC_RB_PREFIX;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

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

    private static final String RELIABLE_TOPIC_NAME = "foo";
    private ReliableTopicProxy<String> topic;
    private Ringbuffer<ReliableTopicMessage> ringbuffer;
    private HazelcastInstance topicOwnerInstance;
    private HazelcastInstance topicBackupInstance;

    @Before
    public void setup() {
        Config config = smallInstanceConfig().addRingBufferConfig(
                new RingbufferConfig(RELIABLE_TOPIC_NAME)
                        .setCapacity(100)
                        .setTimeToLiveSeconds(0)
                        .setBackupCount(0)
                        .setAsyncBackupCount(0));
        final HazelcastInstance[] instances = createHazelcastInstanceFactory(2).newInstances(config);

        warmUpPartitions(instances);
        for (HazelcastInstance instance : instances) {
            final Member owner = instance.getPartitionService().getPartition(TOPIC_RB_PREFIX + RELIABLE_TOPIC_NAME).getOwner();
            final Member localMember = instance.getCluster().getLocalMember();
            if (localMember.equals(owner)) {
                topicOwnerInstance = instance;
            } else {
                topicBackupInstance = instance;
            }
        }

        topic = (ReliableTopicProxy<String>) topicBackupInstance.<String>getReliableTopic(RELIABLE_TOPIC_NAME);
        ringbuffer = topic.ringbuffer;
{'fraction_non_alphanumeric': 0.0813836898395722, 'fraction_numerical': 0.006350267379679145, 'mean_word_length': 3.7349683544303796, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, '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': '5220584', 'n_tokens_mistral': 1679, 'n_tokens_neox': 1633, 'n_words': 396}