noob-se7en commented on code in PR #15028: URL: https://github.com/apache/pinot/pull/15028#discussion_r1952197917
########## pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/KafkaIncreaseDecreasePartitionsIntegrationTest.java: ########## @@ -0,0 +1,158 @@ +/** + * 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.integration.tests; + +import java.io.IOException; +import java.util.concurrent.atomic.AtomicInteger; +import org.apache.pinot.controller.api.resources.PauseStatusDetails; +import org.apache.pinot.controller.api.resources.TableViews; +import org.apache.pinot.spi.config.table.TableConfig; +import org.apache.pinot.spi.data.Schema; +import org.apache.pinot.spi.utils.JsonUtils; +import org.apache.pinot.tools.utils.KafkaStarterUtils; +import org.apache.pinot.util.TestUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testng.annotations.Test; + + +public class KafkaIncreaseDecreasePartitionsIntegrationTest extends BaseRealtimeClusterIntegrationTest { + private static final Logger LOGGER = LoggerFactory.getLogger(KafkaIncreaseDecreasePartitionsIntegrationTest.class); + + private static final String KAFKA_TOPIC = "meetup"; + private static final int NUM_PARTITIONS = 3; + + String getExternalView(String tableName) + throws IOException { + return sendGetRequest(getControllerRequestURLBuilder().forExternalView(tableName)); + } + + void pauseTable(String tableName) + throws IOException { + sendPostRequest(getControllerRequestURLBuilder().forPauseConsumption(tableName)); + TestUtils.waitForCondition((aVoid) -> { + try { + PauseStatusDetails pauseStatusDetails = + JsonUtils.stringToObject(sendGetRequest(getControllerRequestURLBuilder().forPauseStatus(tableName)), + PauseStatusDetails.class); + return pauseStatusDetails.getConsumingSegments().isEmpty(); + } catch (IOException e) { + throw new RuntimeException(e); + } + }, 60_000L, "Failed to pause table: " + tableName); + } + + void resumeTable(String tableName) + throws IOException { + sendPostRequest(getControllerRequestURLBuilder().forResumeConsumption(tableName)); + TestUtils.waitForCondition((aVoid) -> { + try { + PauseStatusDetails pauseStatusDetails = + JsonUtils.stringToObject(sendGetRequest(getControllerRequestURLBuilder().forPauseStatus(tableName)), + PauseStatusDetails.class); + return !pauseStatusDetails.getConsumingSegments().isEmpty(); + } catch (IOException e) { + throw new RuntimeException(e); + } + }, 60_000L, "Failed to pause table: " + tableName); + } + + String createTable() + throws IOException { + Schema schema = createSchema("simpleMeetup_schema.json"); + addSchema(schema); + TableConfig tableConfig = JsonUtils.inputStreamToObject( + getClass().getClassLoader().getResourceAsStream("simpleMeetup_realtime_table_config.json"), TableConfig.class); + addTableConfig(tableConfig); + return tableConfig.getTableName(); + } + + void waitForNumConsumingSegmentsInEV(String tableName, int desiredNumConsumingSegments) { + TestUtils.waitForCondition((aVoid) -> { + try { + AtomicInteger numConsumingSegments = new AtomicInteger(0); + String state = getExternalView(tableName); + TableViews.TableView tableView = JsonUtils.stringToObject(state, TableViews.TableView.class); + tableView._realtime.values().forEach((v) -> { + numConsumingSegments.addAndGet((int) v.values().stream().filter((v1) -> v1.equals("CONSUMING")).count()); + }); + return numConsumingSegments.get() == desiredNumConsumingSegments; + } catch (IOException e) { + LOGGER.error("Exception in waitForNumConsumingSegments: {}", e.getMessage()); + return false; + } + }, 5000, 600_000L, Review Comment: 10 min waiting looks bit high -- 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