<commit_before>package com.hazelcast.client.multimap;

import com.hazelcast.client.HazelcastClient;
import com.hazelcast.core.*;
import com.hazelcast.test.HazelcastParallelClassRunner;
import com.hazelcast.test.annotation.NightlyTest;
import com.hazelcast.test.annotation.ProblematicTest;
import com.hazelcast.test.annotation.QuickTest;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;

import java.util.concurrent.atomic.AtomicInteger;

import static com.hazelcast.test.HazelcastTestSupport.*;
import static com.hazelcast.test.HazelcastTestSupport.randomString;
import static junit.framework.Assert.assertEquals;

@RunWith(HazelcastParallelClassRunner.class)
@Category(QuickTest.class)
public class ClientMultiMapListenerStressTest {

    static final String MAP_NAME = randomString();
    static final int NUMBER_OF_CLIENTS = 1;
    static final int THREADS_PER_CLIENT = 8;

    static HazelcastInstance server;

    @BeforeClass
    public static void init() {
        server = Hazelcast.newHazelcastInstance();
    }

    @AfterClass
    public static void destroy() {
        HazelcastClient.shutdownAll();
        Hazelcast.shutdownAll();
    }


    @Test
    @Category(ProblematicTest.class)
    public void listenerAddStressTest() throws InterruptedException {

        PutItemsThread[] putThreads = new PutItemsThread[NUMBER_OF_CLIENTS * THREADS_PER_CLIENT];

        int idx=0;
        for(int i=0; i<NUMBER_OF_CLIENTS; i++){
            HazelcastInstance client = HazelcastClient.newHazelcastClient();
            for(int j=0; j<THREADS_PER_CLIENT; j++){
                PutItemsThread t = new PutItemsThread(client);
                putThreads[idx++]=t;
            }
        }

        for(int i=0; i<putThreads.length; i++){
            putThreads[i].start();
        }

        assertJoinable(putThreads);

        MultiMap mm = server.getMultiMap(MAP_NAME);
        assertEquals(PutItemsThread.maxItems * putThreads.length, mm.size());

        for(int i=0; i<putThreads.length; i++){
            putThreads[i].assertResult(PutItemsThread.maxItems * putThreads.length);
        }
    }

    public class PutItemsThread extends Thread{

        public static final int maxItems = 1000;

        public final MyEntryListener listener = new MyEntryListener();
        public HazelcastInstance hzInstance;
        public MultiMap mm;
        public String id;

        public PutItemsThread(HazelcastInstance hzInstance){
            this.id = randomString();
            this.hzInstance = hzInstance;
            this.mm = hzInstance.getMultiMap(MAP_NAME);
            mm.addEntryListener(listener, true);
        }

        public void run(){
            for(int i=0; i<maxItems; i++){
                mm.put(id+i, id+i);
            }
        }

        public void assertResult(int target){
            assertEquals(target, listener.add.get());
        }
    }

    static class MyEntryListener implements EntryListener {
<commit_msg>fixed with assert true Eventual<commit_after>package com.hazelcast.client.multimap;

import com.hazelcast.client.HazelcastClient;
import com.hazelcast.core.*;
import com.hazelcast.test.AssertTask;
import com.hazelcast.test.HazelcastParallelClassRunner;
import com.hazelcast.test.annotation.NightlyTest;
import com.hazelcast.test.annotation.QuickTest;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;

import java.util.concurrent.atomic.AtomicInteger;

import static com.hazelcast.test.HazelcastTestSupport.*;
import static com.hazelcast.test.HazelcastTestSupport.randomString;
import static junit.framework.Assert.assertEquals;

@RunWith(HazelcastParallelClassRunner.class)
@Category(NightlyTest.class)
public class ClientMultiMapListenerStressTest {

    static final int MAX_SECONDS = 60 * 10;
    static final String MAP_NAME = randomString();
    static final int NUMBER_OF_CLIENTS = 8;
    static final int THREADS_PER_CLIENT = 16;

    static HazelcastInstance server;

    @BeforeClass
    public static void init() {
        server = Hazelcast.newHazelcastInstance();
    }

    @AfterClass
    public static void destroy() {
        HazelcastClient.shutdownAll();
        Hazelcast.shutdownAll();
    }


    @Test
    public void listenerAddStressTest() throws InterruptedException {

        final PutItemsThread[] putThreads = new PutItemsThread[NUMBER_OF_CLIENTS * THREADS_PER_CLIENT];

        int idx=0;
        for(int i=0; i<NUMBER_OF_CLIENTS; i++){
            HazelcastInstance client = HazelcastClient.newHazelcastClient();
            for(int j=0; j<THREADS_PER_CLIENT; j++){
                PutItemsThread t = new PutItemsThread(client);
                putThreads[idx++]=t;
            }
        }

        for(int i=0; i<putThreads.length; i++){
            putThreads[i].start();
        }

        assertJoinable(MAX_SECONDS, putThreads );

        MultiMap mm = server.getMultiMap(MAP_NAME);
        assertEquals(PutItemsThread.MAX_ITEMS * putThreads.length, mm.size());

        assertTrueEventually(new AssertTask() {

            public void run() throws Exception {
                for(int i=0; i<putThreads.length; i++){
                    putThreads[i].assertResult(PutItemsThread.MAX_ITEMS * putThreads.length);
                }
            }
        });

    }

    public class PutItemsThread extends Thread{

        public static final int MAX_ITEMS = 1000;

        public final MyEntryListener listener = new MyEntryListener();
        public HazelcastInstance hzInstance;
        public MultiMap mm;
        public String id;

        public PutItemsThread(HazelcastInstance hzInstance){
            this.id = randomString();
            this.hzInstance = hzInstance;
            this.mm = hzInstance.getMultiMap(MAP_NAME);
            mm.addEntryListener(listener, true);
        }

        public void run(){
            for(int i=0; i< MAX_ITEMS; i++){
                mm.put(id+i, id+i);
            }
        }

        public void assertResult(int target){
            assertEquals(target, listener.add.get());
        }
    }

    static class MyEntryListener implements EntryListener {

{'fraction_non_alphanumeric': 0.0933248971844353, 'fraction_numerical': 0.0045871559633027525, 'mean_word_length': 2.8767627222562844, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '5112128', 'n_tokens_mistral': 1906, 'n_tokens_neox': 1850, 'n_words': 373}