This is an automated email from the ASF dual-hosted git repository.

clebertsuconic pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git


The following commit(s) were added to refs/heads/main by this push:
     new f082b9c5d1 ARTEMIS-4199 Adding test for open transaction on reset call
f082b9c5d1 is described below

commit f082b9c5d167157e9cb63e630e797722819da70c
Author: Clebert Suconic <[email protected]>
AuthorDate: Mon May 15 09:34:09 2023 -0400

    ARTEMIS-4199 Adding test for open transaction on reset call
---
 .../cursor/impl/PageSubscriptionCounterImpl.java   |  2 +-
 .../impl/PageSubscriptionCounterImplAccessor.java  | 25 ++++++++++++++++
 .../integration/paging/PageCounterRebuildTest.java | 35 ++++++++++++++++++++++
 3 files changed, 61 insertions(+), 1 deletion(-)

diff --git 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/cursor/impl/PageSubscriptionCounterImpl.java
 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/cursor/impl/PageSubscriptionCounterImpl.java
index df69f0e96c..cb4b9750c7 100644
--- 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/cursor/impl/PageSubscriptionCounterImpl.java
+++ 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/cursor/impl/PageSubscriptionCounterImpl.java
@@ -226,7 +226,7 @@ public class PageSubscriptionCounterImpl extends 
BasePagingCounter {
       tx.commit();
    }
 
-   private void reset() throws Exception {
+   void reset() throws Exception {
       Transaction tx = new TransactionImpl(storage);
 
       delete(tx, true);
diff --git 
a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/core/paging/cursor/impl/PageSubscriptionCounterImplAccessor.java
 
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/core/paging/cursor/impl/PageSubscriptionCounterImplAccessor.java
new file mode 100644
index 0000000000..92e547dff7
--- /dev/null
+++ 
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/core/paging/cursor/impl/PageSubscriptionCounterImplAccessor.java
@@ -0,0 +1,25 @@
+/*
+ * 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.core.paging.cursor.impl;
+
+public class PageSubscriptionCounterImplAccessor {
+
+   public static void reset(PageSubscriptionCounterImpl impl) throws Exception 
{
+      impl.reset();
+   }
+}
\ No newline at end of file
diff --git 
a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/paging/PageCounterRebuildTest.java
 
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/paging/PageCounterRebuildTest.java
index 2369e47269..d84ec4f142 100644
--- 
a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/paging/PageCounterRebuildTest.java
+++ 
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/paging/PageCounterRebuildTest.java
@@ -30,10 +30,12 @@ import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicLong;
 
 import org.apache.activemq.artemis.api.core.QueueConfiguration;
 import org.apache.activemq.artemis.api.core.RoutingType;
 import 
org.apache.activemq.artemis.core.paging.cursor.impl.PageSubscriptionCounterImpl;
+import 
org.apache.activemq.artemis.core.paging.cursor.impl.PageSubscriptionCounterImplAccessor;
 import org.apache.activemq.artemis.core.persistence.StorageManager;
 import org.apache.activemq.artemis.core.server.ActiveMQServer;
 import org.apache.activemq.artemis.core.server.Queue;
@@ -46,6 +48,8 @@ import org.apache.activemq.artemis.utils.ReusableLatch;
 import org.junit.Assert;
 import org.junit.Test;
 import org.mockito.Mockito;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -120,6 +124,37 @@ public class PageCounterRebuildTest extends 
ActiveMQTestBase {
       Assert.assertEquals(0, errors.get());
    }
 
+   @Test
+   public void testResetSubscriptionCounter() throws Exception {
+      StorageManager mockStorage = Mockito.mock(StorageManager.class);
+
+      PageSubscriptionCounterImpl nonPersistentPagingCounter = new 
PageSubscriptionCounterImpl(mockStorage, 33);
+
+      AtomicInteger called = new AtomicInteger(0);
+
+      AtomicLong generate = new AtomicLong(1);
+
+      Mockito.doAnswer(new Answer<Long>() {
+         @Override
+         public Long answer(InvocationOnMock invocationOnMock) throws 
Throwable {
+            return generate.incrementAndGet();
+         }
+      }).when(mockStorage).generateID();
+
+      Mockito.doAnswer(new Answer<Void>() {
+         @Override
+         public Void answer(InvocationOnMock invocationOnMock) throws 
Throwable {
+            called.incrementAndGet();
+
+            return null;
+         }
+      }).when(mockStorage).commit(Mockito.anyLong());
+
+      PageSubscriptionCounterImplAccessor.reset(nonPersistentPagingCounter);
+
+      Assert.assertEquals(1, called.get());
+   }
+
    @Test
    public void testRebuildCounter() throws Exception {
       ActiveMQServer server = createServer(true, true);

Reply via email to