ARTEMIS-4199 Adding test for open transaction on reset call

This commit is contained in:
Clebert Suconic 2023-05-15 09:34:09 -04:00 committed by clebertsuconic
parent bea39f6692
commit f082b9c5d1
3 changed files with 61 additions and 1 deletions

View File

@ -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);

View File

@ -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();
}
}

View File

@ -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);