Skip to content

Commit

Permalink
Upgrade to Mockito 2.x (apache#4671)
Browse files Browse the repository at this point in the history
Upgrading to Mockito 2.28 and PowerMock 2.0. This a pre-step to be able to run CI with Java 11 / 12
  • Loading branch information
merlimat authored and jiazhai committed Jul 10, 2019
1 parent 363b6ba commit 108780c
Show file tree
Hide file tree
Showing 98 changed files with 755 additions and 2,022 deletions.
9 changes: 8 additions & 1 deletion buildtools/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.13.1</version>
<version>6.14.3</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
Expand Down Expand Up @@ -67,6 +67,13 @@
<header>../src/license-header.txt</header>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
<extensions>
<extension>
Expand Down
4 changes: 2 additions & 2 deletions distribution/server/src/assemble/LICENSE.bin.txt
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ The Apache Software License, Version 2.0
* Google Error Prone Annotations - com.google.errorprone-error_prone_annotations-2.2.0.jar
* OkHttp - com.squareup.okhttp-okhttp-2.5.0.jar
* Okio - com.squareup.okio-okio-1.13.0.jar
* Javassist -- org.javassist-javassist-3.21.0-GA.jar
* Javassist -- org.javassist-javassist-3.25.0-GA.jar
* gRPC
- io.grpc-grpc-all-1.18.0.jar
- io.grpc-grpc-auth-1.18.0.jar
Expand Down Expand Up @@ -455,7 +455,7 @@ The Apache Software License, Version 2.0
* Snappy Java
- org.xerial.snappy-snappy-java-1.1.1.3.jar
* Objenesis
- org.objenesis-objenesis-2.1.jar
- org.objenesis-objenesis-2.6.jar
* Squareup
- com.squareup.okhttp-logging-interceptor-2.7.5.jar
- com.squareup.okhttp-okhttp-ws-2.7.5.jar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ public CompletableFuture<Long> tryReadLastAddConfirmedAsync() {

@Override
public long getLastAddConfirmed() {
return entries.get(entries.size() - 1).getEntryId();
if (entries.isEmpty()) {
return -1;
} else {
return entries.get(entries.size() - 1).getEntryId();
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,24 @@
*/
package org.apache.bookkeeper.mledger.impl;

import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyLong;
import static org.mockito.Mockito.*;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.testng.Assert.assertEquals;

import io.netty.buffer.Unpooled;

import java.lang.reflect.Method;
import java.util.List;
import java.util.Vector;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CountDownLatch;

import org.apache.bookkeeper.client.BKException.BKNoSuchLedgerExistsException;
import org.apache.bookkeeper.client.api.BKException;
import org.apache.bookkeeper.client.api.LedgerEntries;
import org.apache.bookkeeper.client.api.LedgerEntry;
import org.apache.bookkeeper.client.api.ReadHandle;
Expand All @@ -39,8 +44,6 @@
import org.apache.bookkeeper.mledger.ManagedLedgerException;
import org.apache.bookkeeper.test.MockedBookKeeperTestCase;
import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
*/
package org.apache.bookkeeper.mledger.impl;

import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
Expand Down Expand Up @@ -95,9 +95,9 @@
import org.apache.bookkeeper.test.MockedBookKeeperTestCase;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.pulsar.common.allocator.PulsarByteBufAllocator;
import org.apache.pulsar.common.protocol.ByteBufPair;
import org.apache.pulsar.common.api.proto.PulsarApi.CommandSubscribe.InitialPosition;
import org.apache.pulsar.common.api.proto.PulsarApi.MessageMetadata;
import org.apache.pulsar.common.protocol.ByteBufPair;
import org.apache.pulsar.common.util.protobuf.ByteBufCodedOutputStream;
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.KeeperException.Code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
*/
package org.apache.bookkeeper.mledger.impl;

import static org.mockito.Matchers.anyLong;
import static org.mockito.Matchers.anyMap;
import static org.mockito.Matchers.anyObject;
import static org.mockito.Matchers.eq;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyMap;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
Expand All @@ -32,7 +32,6 @@
import io.netty.buffer.ByteBuf;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.NavigableMap;
Expand All @@ -49,23 +48,16 @@
import org.apache.bookkeeper.client.api.ReadHandle;
import org.apache.bookkeeper.client.impl.LedgerEntriesImpl;
import org.apache.bookkeeper.client.impl.LedgerEntryImpl;

import org.apache.bookkeeper.mledger.Entry;
import org.apache.bookkeeper.mledger.LedgerOffloader;
import org.apache.bookkeeper.mledger.ManagedCursor;
import org.apache.bookkeeper.mledger.ManagedLedgerConfig;
import org.apache.bookkeeper.net.BookieSocketAddress;
import org.apache.bookkeeper.test.MockedBookKeeperTestCase;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.testng.Assert;
import org.testng.annotations.Test;

public class OffloadPrefixReadTest extends MockedBookKeeperTestCase {
private static final Logger log = LoggerFactory.getLogger(OffloadPrefixReadTest.class);

@Test
public void testOffloadRead() throws Exception {
MockLedgerOffloader offloader = spy(new MockLedgerOffloader());
Expand Down Expand Up @@ -101,21 +93,21 @@ public void testOffloadRead() throws Exception {
Assert.assertEquals(new String(e.getData()), "entry-" + i++);
}
verify(offloader, times(1))
.readOffloaded(anyLong(), anyObject(), anyMap());
.readOffloaded(anyLong(), any(), anyMap());
verify(offloader).readOffloaded(anyLong(), eq(firstLedgerUUID), anyMap());

for (Entry e : cursor.readEntries(10)) {
Assert.assertEquals(new String(e.getData()), "entry-" + i++);
}
verify(offloader, times(2))
.readOffloaded(anyLong(), anyObject(), anyMap());
.readOffloaded(anyLong(), any(), anyMap());
verify(offloader).readOffloaded(anyLong(), eq(secondLedgerUUID), anyMap());

for (Entry e : cursor.readEntries(5)) {
Assert.assertEquals(new String(e.getData()), "entry-" + i++);
}
verify(offloader, times(2))
.readOffloaded(anyLong(), anyObject(), anyMap());
.readOffloaded(anyLong(), any(), anyMap());
}

static class MockLedgerOffloader implements LedgerOffloader {
Expand Down
21 changes: 15 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ flexible messaging model and an intuitive client API.</description>
<disruptor.version>3.4.0</disruptor.version>
<testcontainers.version>1.11.2</testcontainers.version>
<kerby.version>1.1.1</kerby.version>
<testng.version>6.14.3</testng.version>
<mockito.version>2.28.2</mockito.version>
<powermock.version>2.0.2</powermock.version>
<javassist.version>3.25.0-GA</javassist.version>

<!-- Plugin dependencies -->
<protobuf-maven-plugin.version>0.6.1</protobuf-maven-plugin.version>
Expand Down Expand Up @@ -239,25 +243,25 @@ flexible messaging model and an intuitive client API.</description>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
<version>${testng.version}</version>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>1.10.19</version>
<version>${mockito.version}</version>
</dependency>

<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>1.7.3</version>
<artifactId>powermock-api-mockito2</artifactId>
<version>${powermock.version}</version>
</dependency>

<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-testng</artifactId>
<version>1.7.3</version>
<version>${powermock.version}</version>
</dependency>

<dependency>
Expand Down Expand Up @@ -1003,6 +1007,11 @@ flexible messaging model and an intuitive client API.</description>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>${joda.version}</version>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>${javassist.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
Expand Down Expand Up @@ -1030,7 +1039,7 @@ flexible messaging model and an intuitive client API.</description>

<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<artifactId>powermock-api-mockito2</artifactId>
<scope>test</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
package org.apache.pulsar.broker.admin;

import static org.mockito.Matchers.anyObject;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
Expand All @@ -29,33 +29,23 @@

import java.util.concurrent.CompletableFuture;

import lombok.extern.slf4j.Slf4j;

import org.apache.bookkeeper.mledger.ManagedLedgerInfo;
import org.apache.bookkeeper.mledger.LedgerOffloader;
import org.apache.bookkeeper.mledger.ManagedLedgerInfo;
import org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest;
import org.apache.pulsar.client.admin.LongRunningProcessStatus;
import org.apache.pulsar.client.admin.PulsarAdminException.ConflictException;
import org.apache.pulsar.client.api.MessageId;
import org.apache.pulsar.client.api.Producer;
import org.apache.pulsar.client.api.PulsarClient;
import org.apache.pulsar.client.impl.MessageIdImpl;
import org.apache.pulsar.common.naming.TopicName;
import org.apache.pulsar.common.policies.data.ClusterData;
import org.apache.pulsar.common.policies.data.TenantInfo;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

@Slf4j
public class AdminApiOffloadTest extends MockedPulsarServiceBaseTest {

private static final Logger LOG = LoggerFactory.getLogger(AdminApiOffloadTest.class);

@BeforeMethod
@Override
public void setup() throws Exception {
Expand Down Expand Up @@ -84,10 +74,10 @@ private void testOffload(String topicName, String mlName) throws Exception {
doReturn(offloader).when(pulsar).getManagedLedgerOffloader();

CompletableFuture<Void> promise = new CompletableFuture<>();
doReturn(promise).when(offloader).offload(anyObject(), anyObject(), anyObject());
doReturn(promise).when(offloader).offload(any(), any(), any());

MessageId currentId = MessageId.latest;
try (Producer p = pulsarClient.newProducer().topic(topicName).enableBatching(false).create()) {
try (Producer<byte[]> p = pulsarClient.newProducer().topic(topicName).enableBatching(false).create()) {
for (int i = 0; i < 15; i++) {
currentId = p.send("Foobar".getBytes());
}
Expand Down Expand Up @@ -120,7 +110,7 @@ private void testOffload(String topicName, String mlName) throws Exception {

// Try again
doReturn(CompletableFuture.completedFuture(null))
.when(offloader).offload(anyObject(), anyObject(), anyObject());
.when(offloader).offload(any(), any(), any());

admin.topics().triggerOffload(topicName, currentId);

Expand All @@ -131,7 +121,7 @@ private void testOffload(String topicName, String mlName) throws Exception {
Assert.assertEquals(firstUnoffloaded.getLedgerId(), info.ledgers.get(1).ledgerId);
Assert.assertEquals(firstUnoffloaded.getEntryId(), 0);

verify(offloader, times(2)).offload(anyObject(), anyObject(), anyObject());
verify(offloader, times(2)).offload(any(), any(), any());
}


Expand Down
Loading

0 comments on commit 108780c

Please sign in to comment.