clebertsuconic commented on code in PR #6323: URL: https://github.com/apache/artemis/pull/6323#discussion_r3028071971
########## tests/soak-tests/src/test/java/org/apache/activemq/artemis/tests/soak/paging/AMQPGlobalMaxTest.java: ########## @@ -0,0 +1,356 @@ +/* + * 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.activemq.artemis.tests.soak.paging; + +import javax.jms.Connection; +import javax.jms.ConnectionFactory; +import javax.jms.Message; +import javax.jms.MessageConsumer; +import javax.jms.MessageProducer; +import javax.jms.Session; +import java.io.File; +import java.lang.invoke.MethodHandles; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.BiConsumer; +import java.util.function.BiFunction; + +import org.apache.activemq.artemis.api.core.management.SimpleManagement; +import org.apache.activemq.artemis.cli.commands.helper.HelperCreate; +import org.apache.activemq.artemis.tests.soak.SoakTestBase; +import org.apache.activemq.artemis.tests.util.CFUtil; +import org.apache.activemq.artemis.utils.FileUtil; +import org.apache.activemq.artemis.utils.RandomUtil; +import org.apache.activemq.artemis.utils.Wait; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + +public class AMQPGlobalMaxTest extends SoakTestBase { + + private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); + + public static final String QUEUE_NAME = "simpleTest"; + public static final String SERVER_NAME = "global-max-test"; + private static File serverLocation; + + private int lastMessageSent; + + String memoryUsed; + long highestMemoryUsed; + + boolean hasOME = false; + + private Process server; + + private long avgSizeFirstEstimate; + + public static void createServers(long globalMaxSize, String vmSize) throws Exception { + serverLocation = getFileServerLocation(SERVER_NAME); + deleteDirectory(serverLocation); + + HelperCreate cliCreateServer = helperCreate(); + cliCreateServer.setUseAIO(false).setAllowAnonymous(true).setNoWeb(true).setArtemisInstance(serverLocation); + // to speedup producers + cliCreateServer.addArgs("--no-fsync"); + cliCreateServer.addArgs("--queues", QUEUE_NAME); + cliCreateServer.addArgs("--global-max-size", String.valueOf(globalMaxSize)); + // limiting memory to make the test more predictable + cliCreateServer.addArgs("--java-memory", vmSize); + cliCreateServer.createServer(); + + FileUtil.findReplace(new File(serverLocation, "/etc/artemis.profile"), "-Xms512M", "-Xms10M -verbose:gc"); + } + + @Test + public void testValidateMemoryEstimateLargeAMQP() throws Exception { + validateOME((s, i) -> { + try { + Message m = s.createTextMessage("a".repeat(200 * 1024)); + m.setStringProperty("prop", "a".repeat(10 * 1024)); + m.setStringProperty("prop", "b".repeat(10 * 1024)); + return m; + } catch (Exception e) { + fail(e.getMessage()); + return null; + } + }, "35M", 1, 100); + } + + private void validateOME(BiFunction<Session, Integer, Message> messageCreator, String vmSize, int commitInterval, int printInterval) throws Exception { + // making the broker to OME on purpose + // this is to help us calculate the size of each message + // for this reason the global-max-size is set really high on this test + createServers(1024 * 1024 * 1024, vmSize); + startServerWithLog(); + + executeTest(messageCreator, (a, b) -> { }, vmSize, commitInterval, printInterval, 20_000_000, TimeUnit.MINUTES.toMillis(10), true); + } + + @Test + public void testValidateMemoryEstimateAMQP() throws Exception { + validateOME((s, i) -> { + try { + Message m = s.createMessage(); + for (int randomI = 0; randomI < 10; randomI++) { + m.setStringProperty("string" + i, RandomUtil.randomUUIDString()); + m.setLongProperty("myLong" + i, RandomUtil.randomLong()); + } + return m; + } catch (Throwable e) { + Assertions.fail(e.getMessage()); + return null; + } + }, "256M", 1000, 1000); + } + + private void startServerWithLog() throws Exception { + server = startServer(SERVER_NAME, 0, 5000, null, s -> { + logger.debug("{}", s); + if (s.contains("GC") && s.contains("->")) { + AMQPGlobalMaxTest.this.memoryUsed = parseMemoryUsageFromGCLOG(s); Review Comment: it doesn't really matter TBH.. those are just estimates anyway. I can make the value volatile perhaps.. but it doesn't need an Atomic operation. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
