gemmellr commented on a change in pull request #3863:
URL: https://github.com/apache/activemq-artemis/pull/3863#discussion_r760084361



##########
File path: 
artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/impl/PagingStoreImpl.java
##########
@@ -1153,6 +1161,31 @@ public boolean isFull() {
       return maxSize > 0 && getAddressSize() > maxSize || 
pagingManager.isGlobalFull();
    }
 
+
+   @Override
+   public int getAddressLimitPercent() {
+      final long currentUsage = getAddressSize();
+      if (currentUsage != 0) {
+         if (maxSize > 0) {
+            return Math.toIntExact((currentUsage / maxSize) * 100);

Review comment:
       Or 1, if currentUsage is the same (or bigger but < double).
   
   Phrased another way: unit tests missing with 0% !=  x != 100% checks also?
   
   (the currentUsage != 0 could probably go away too)

##########
File path: 
tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/balancing/ElasticQueueTest.java
##########
@@ -0,0 +1,697 @@
+/*
+ * 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.integration.balancing;
+
+import javax.jms.BytesMessage;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageListener;
+import javax.jms.MessageProducer;
+import javax.jms.ResourceAllocationException;
+import javax.jms.Session;
+import javax.management.MBeanServer;
+import javax.management.MBeanServerFactory;
+import javax.security.auth.Subject;
+import java.io.File;
+import java.net.URI;
+import java.util.Set;
+import java.util.Stack;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration;
+import org.apache.activemq.artemis.api.core.SimpleString;
+import org.apache.activemq.artemis.api.core.management.AddressControl;
+import org.apache.activemq.artemis.api.core.management.BrokerBalancerControl;
+import org.apache.activemq.artemis.api.core.management.ObjectNameBuilder;
+import org.apache.activemq.artemis.core.config.Configuration;
+import 
org.apache.activemq.artemis.core.config.balancing.BrokerBalancerConfiguration;
+import org.apache.activemq.artemis.core.config.impl.ConfigurationImpl;
+import org.apache.activemq.artemis.core.security.CheckType;
+import org.apache.activemq.artemis.core.security.Role;
+import org.apache.activemq.artemis.core.server.balancing.targets.TargetKey;
+import org.apache.activemq.artemis.core.server.embedded.EmbeddedActiveMQ;
+import org.apache.activemq.artemis.core.settings.impl.AddressFullMessagePolicy;
+import org.apache.activemq.artemis.core.settings.impl.AddressSettings;
+import org.apache.activemq.artemis.core.settings.impl.SlowConsumerPolicy;
+import org.apache.activemq.artemis.spi.core.protocol.RemotingConnection;
+import org.apache.activemq.artemis.spi.core.security.ActiveMQSecurityManager5;
+import org.apache.activemq.artemis.spi.core.security.jaas.RolePrincipal;
+import org.apache.activemq.artemis.spi.core.security.jaas.UserPrincipal;
+import 
org.apache.activemq.artemis.tests.integration.management.ManagementControlHelper;
+import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
+import org.apache.activemq.artemis.utils.Wait;
+import org.apache.qpid.jms.JmsConnection;
+import org.apache.qpid.jms.JmsConnectionFactory;
+import org.apache.qpid.jms.JmsConnectionListener;
+import org.apache.qpid.jms.message.JmsInboundMessageDispatch;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class ElasticQueueTest extends ActiveMQTestBase {
+
+   static final String qName = "EQ";
+   static final SimpleString qNameSimple = SimpleString.toSimpleString(qName);
+
+   final int base_port = 61616;
+   final int opTimeoutMillis = 2000;
+   final Stack<EmbeddedActiveMQ> nodes = new Stack<>();

Review comment:
       Does anything clean these up when the test fails mid-way?

##########
File path: 
artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/impl/PagingStoreImpl.java
##########
@@ -695,6 +697,14 @@ public boolean checkMemory(final Runnable 
runWhenAvailable) {
    @Override
    public boolean checkMemory(boolean runOnFailure, final Runnable 
runWhenAvailable) {
 
+      if (blocked) {
+         if (runWhenAvailable != null) {
+            
onMemoryFreedRunnables.add(AtomicRunnable.checkAtomic(runWhenAvailable));

Review comment:
       unBlock() would need to do the reverse too I guess, check if `blocking`. 

##########
File path: 
tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/balancing/ElasticQueueTest.java
##########
@@ -0,0 +1,697 @@
+/*
+ * 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.integration.balancing;
+
+import javax.jms.BytesMessage;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageListener;
+import javax.jms.MessageProducer;
+import javax.jms.ResourceAllocationException;
+import javax.jms.Session;
+import javax.management.MBeanServer;
+import javax.management.MBeanServerFactory;
+import javax.security.auth.Subject;
+import java.io.File;
+import java.net.URI;
+import java.util.Set;
+import java.util.Stack;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration;
+import org.apache.activemq.artemis.api.core.SimpleString;
+import org.apache.activemq.artemis.api.core.management.AddressControl;
+import org.apache.activemq.artemis.api.core.management.BrokerBalancerControl;
+import org.apache.activemq.artemis.api.core.management.ObjectNameBuilder;
+import org.apache.activemq.artemis.core.config.Configuration;
+import 
org.apache.activemq.artemis.core.config.balancing.BrokerBalancerConfiguration;
+import org.apache.activemq.artemis.core.config.impl.ConfigurationImpl;
+import org.apache.activemq.artemis.core.security.CheckType;
+import org.apache.activemq.artemis.core.security.Role;
+import org.apache.activemq.artemis.core.server.balancing.targets.TargetKey;
+import org.apache.activemq.artemis.core.server.embedded.EmbeddedActiveMQ;
+import org.apache.activemq.artemis.core.settings.impl.AddressFullMessagePolicy;
+import org.apache.activemq.artemis.core.settings.impl.AddressSettings;
+import org.apache.activemq.artemis.core.settings.impl.SlowConsumerPolicy;
+import org.apache.activemq.artemis.spi.core.protocol.RemotingConnection;
+import org.apache.activemq.artemis.spi.core.security.ActiveMQSecurityManager5;
+import org.apache.activemq.artemis.spi.core.security.jaas.RolePrincipal;
+import org.apache.activemq.artemis.spi.core.security.jaas.UserPrincipal;
+import 
org.apache.activemq.artemis.tests.integration.management.ManagementControlHelper;
+import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
+import org.apache.activemq.artemis.utils.Wait;
+import org.apache.qpid.jms.JmsConnection;
+import org.apache.qpid.jms.JmsConnectionFactory;
+import org.apache.qpid.jms.JmsConnectionListener;
+import org.apache.qpid.jms.message.JmsInboundMessageDispatch;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class ElasticQueueTest extends ActiveMQTestBase {
+
+   static final String qName = "EQ";
+   static final SimpleString qNameSimple = SimpleString.toSimpleString(qName);
+
+   final int base_port = 61616;
+   final int opTimeoutMillis = 2000;
+   final Stack<EmbeddedActiveMQ> nodes = new Stack<>();
+   private final String balancerConfigName = "role_name_sharder";
+
+   String urlForNodes(Stack<EmbeddedActiveMQ> nodes) {
+      StringBuilder builder = new StringBuilder("failover:(");
+      int port_start = base_port;
+      for (EmbeddedActiveMQ activeMQ : nodes) {
+         if (port_start != base_port) {
+            builder.append(",");
+         }
+         builder.append("amqp://localhost:" + (port_start++));
+      }
+      // fast reconnect, randomize to get to all brokers and timeout sends 
that block on no credit
+      
builder.append(")?failover.maxReconnectDelay=2000&failover.randomize=true&jms.sendTimeout="
 + opTimeoutMillis);
+      return builder.toString();
+   }
+
+   // allow tracking of failover reconnects
+   class ConnectionListener implements JmsConnectionListener {
+
+      AtomicInteger connectionCount;
+
+      ConnectionListener(AtomicInteger connectionCount) {
+         this.connectionCount = connectionCount;
+      }
+
+      @Override
+      public void onConnectionEstablished(URI uri) {
+      }
+
+      @Override
+      public void onConnectionFailure(Throwable throwable) {
+      }
+
+      @Override
+      public void onConnectionInterrupted(URI uri) {
+      }
+
+      @Override
+      public void onConnectionRestored(URI uri) {
+         connectionCount.incrementAndGet();
+      }
+
+      @Override
+      public void onInboundMessage(JmsInboundMessageDispatch 
jmsInboundMessageDispatch) {
+      }
+
+      @Override
+      public void onSessionClosed(Session session, Throwable throwable) {
+      }
+
+      @Override
+      public void onConsumerClosed(MessageConsumer messageConsumer, Throwable 
throwable) {
+      }
+
+      @Override
+      public void onProducerClosed(MessageProducer messageProducer, Throwable 
throwable) {
+      }
+   }
+
+   // slow consumer
+   class EQConsumer extends Thread {

Review comment:
       Probably nicer to use an executor which can then be cleaned up afterwards




-- 
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]


Reply via email to