You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cl...@apache.org on 2020/03/11 15:32:55 UTC

[activemq-artemis] branch master updated: ARTEMIS-2652 Fix PageCursorProviderImplTest on IBM JVM

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 951b5d5  ARTEMIS-2652 Fix PageCursorProviderImplTest on IBM JVM
     new 58c75f7  This closes #3013
951b5d5 is described below

commit 951b5d5deddd3b2bd0b736474be6ddadb4c71892
Author: brusdev <br...@gmail.com>
AuthorDate: Wed Mar 11 15:23:59 2020 +0100

    ARTEMIS-2652 Fix PageCursorProviderImplTest on IBM JVM
    
    Replace the page mock to fix an incompatibility between IBM JDK and Mockito.
---
 .../cursor/impl/PageCursorProviderImplTest.java    | 33 ++++++++++++++++------
 1 file changed, 24 insertions(+), 9 deletions(-)

diff --git a/artemis-server/src/test/java/org/apache/activemq/artemis/core/paging/cursor/impl/PageCursorProviderImplTest.java b/artemis-server/src/test/java/org/apache/activemq/artemis/core/paging/cursor/impl/PageCursorProviderImplTest.java
index 5a75241..9437a7b 100644
--- a/artemis-server/src/test/java/org/apache/activemq/artemis/core/paging/cursor/impl/PageCursorProviderImplTest.java
+++ b/artemis-server/src/test/java/org/apache/activemq/artemis/core/paging/cursor/impl/PageCursorProviderImplTest.java
@@ -18,6 +18,9 @@ package org.apache.activemq.artemis.core.paging.cursor.impl;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 
+import org.apache.activemq.artemis.api.core.SimpleString;
+import org.apache.activemq.artemis.core.io.SequentialFile;
+import org.apache.activemq.artemis.core.io.SequentialFileFactory;
 import org.apache.activemq.artemis.core.paging.PagingStore;
 import org.apache.activemq.artemis.core.paging.cursor.PageCache;
 import org.apache.activemq.artemis.core.paging.impl.Page;
@@ -26,7 +29,6 @@ import org.apache.activemq.artemis.utils.actors.ArtemisExecutor;
 import org.junit.Assert;
 import org.junit.Test;
 
-import static java.util.Collections.emptyList;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.anyInt;
 import static org.mockito.ArgumentMatchers.anyLong;
@@ -45,11 +47,15 @@ public class PageCursorProviderImplTest {
       final PageCursorProviderImpl pageCursorProvider = new PageCursorProviderImpl(pagingStore, storageManager, artemisExecutor, 2);
       when(pagingStore.getCurrentWritingPage()).thenReturn(pages);
       when(pagingStore.checkPageFileExists(anyInt())).thenReturn(true);
-      final Page firstPage = mock(Page.class);
-      when(firstPage.getPageId()).thenReturn(1);
+      SequentialFileFactory sequentialFileFactory = mock(SequentialFileFactory.class);
+      SequentialFile firstPageFile = mock(SequentialFile.class);
+      when(firstPageFile.size()).thenReturn(0L);
+      Page firstPage = new Page(new SimpleString("StorageManager"), storageManager, sequentialFileFactory, firstPageFile, 1);
       when(pagingStore.createPage(1)).thenReturn(firstPage);
-      final Page secondPage = mock(Page.class);
-      when(secondPage.getPageId()).thenReturn(2);
+      SequentialFile secondPageFile = mock(SequentialFile.class);
+      when(secondPageFile.size()).thenReturn(0L);
+      when(secondPageFile.isOpen()).thenReturn(true);
+      Page secondPage = new Page(new SimpleString("StorageManager"), storageManager, sequentialFileFactory, secondPageFile, 2);
       when(pagingStore.createPage(2)).thenReturn(secondPage);
       final CountDownLatch finishFirstPageRead = new CountDownLatch(1);
       final Thread concurrentRead = new Thread(() -> {
@@ -61,10 +67,19 @@ public class PageCursorProviderImplTest {
          }
       });
       try {
-         when(firstPage.read(storageManager)).then(invocationOnMock -> {
-            concurrentRead.start();
-            finishFirstPageRead.await();
-            return emptyList();
+         when(firstPageFile.isOpen()).then(invocationOnMock -> {
+            boolean pageReading = false;
+            for (StackTraceElement element : Thread.currentThread().getStackTrace()) {
+               if (element.getClassName().compareTo(Page.class.getName()) == 0 && element.getMethodName().compareTo("read") == 0) {
+                  pageReading = true;
+                  break;
+               }
+            }
+            if (pageReading) {
+               concurrentRead.start();
+               finishFirstPageRead.await();
+            }
+            return true;
          });
          Assert.assertNotNull(pageCursorProvider.getPageCache(1));
       } finally {