atris commented on code in PR #8636: URL: https://github.com/apache/pinot/pull/8636#discussion_r865234082
########## pinot-segment-local/src/test/java/org/apache/pinot/segment/local/realtime/impl/invertedindex/RealtimeNativeTextIndexConcurrentTest.java: ########## @@ -0,0 +1,306 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.pinot.segment.local.realtime.impl.invertedindex; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; +import java.util.concurrent.ConcurrentSkipListSet; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import static org.testng.AssertJUnit.assertEquals; +import static org.testng.AssertJUnit.assertTrue; + + +public class RealtimeNativeTextIndexConcurrentTest { + private ExecutorService _threadPool; + private Set<String> _resultSet; + + @BeforeClass + private void setup() { + _threadPool = Executors.newFixedThreadPool(10); + _resultSet = new ConcurrentSkipListSet<>(); + } + + @AfterClass + private void shutDown() { + _threadPool.shutdown(); + } + + @Test + public void testConcurrentWriteAndRead() + throws InterruptedException, IOException { + CountDownLatch countDownLatch = new CountDownLatch(2); + List<String> words = new ArrayList<>(); + words.add("ab"); + words.add("abba"); + words.add("aba"); + words.add("bab"); + words.add("cdd"); + words.add("efg"); + + try (RealtimeNativeTextIndex textIndex = new RealtimeNativeTextIndex("testFSTColumn")) { + _threadPool.submit(() -> { + try { + performReads(textIndex, words, 10, 200, countDownLatch); + } catch (InterruptedException e) { + e.printStackTrace(); + } + }); + + _threadPool.submit(() -> { + try { + performWrites(textIndex, words, 10, countDownLatch); + } catch (InterruptedException e) { + e.printStackTrace(); + } + }); + + countDownLatch.await(); + } + + assertEquals(_resultSet.size(), words.size()); + + assertTrue("ab not found in result set", _resultSet.contains("ab")); + assertTrue("abba not found in result set", _resultSet.contains("abba")); + assertTrue("aba not found in result set", _resultSet.contains("aba")); + assertTrue("bab not found in result set", _resultSet.contains("bab")); + assertTrue("cdd not found in result set", _resultSet.contains("cdd")); + assertTrue("efg not found in result set", _resultSet.contains("efg")); + } + + @Test + public void testConcurrentWriteWithMultipleThreads() + throws InterruptedException, IOException { + List<String> firstThreadWords = new ArrayList<>(); + List<String> secondThreadWords = new ArrayList<>(); + List<String> mergedThreadWords = new ArrayList<>(); + CountDownLatch countDownLatch = new CountDownLatch(3); + firstThreadWords.add("ab"); + firstThreadWords.add("abba"); + firstThreadWords.add("aba"); + secondThreadWords.add("bab"); + secondThreadWords.add("cdd"); + secondThreadWords.add("efg"); + + mergedThreadWords.addAll(firstThreadWords); + mergedThreadWords.addAll(secondThreadWords); + + try (RealtimeNativeTextIndex textIndex = new RealtimeNativeTextIndex("testFSTColumn")) { + _threadPool.submit(() -> { + try { + performReads(textIndex, mergedThreadWords, 10, 200, countDownLatch); + } catch (InterruptedException e) { + e.printStackTrace(); + } + }); + + _threadPool.submit(() -> { + try { + performWrites(textIndex, firstThreadWords, 10, countDownLatch); + } catch (InterruptedException e) { + e.printStackTrace(); + } + }); + + _threadPool.submit(() -> { + try { + performWrites(textIndex, secondThreadWords, 10, countDownLatch); + } catch (InterruptedException e) { + e.printStackTrace(); + } + }); + + countDownLatch.await(); + } + + assertEquals(_resultSet.size(), mergedThreadWords.size()); + + assertTrue("ab not found in result set", _resultSet.contains("ab")); Review Comment: That's the message that will be shown if the element is not found -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org