Skip to content

Commit

Permalink
Enable CheckStyle Plugin in Pulsar Test Mocks (apache#13581)
Browse files Browse the repository at this point in the history
  • Loading branch information
goflutterjava authored Jan 4, 2022
1 parent 634ce83 commit 8319e8a
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 36 deletions.
18 changes: 18 additions & 0 deletions testmocks/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,22 @@
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<executions>
<execution>
<id>checkstyle</id>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ public ClientConfiguration getConf() {
return super.getConf();
}

Map<Long, PulsarMockLedgerHandle> ledgers = new ConcurrentHashMap<>();
AtomicLong sequence = new AtomicLong(3);
final Map<Long, PulsarMockLedgerHandle> ledgers = new ConcurrentHashMap<>();
final AtomicLong sequence = new AtomicLong(3);

CompletableFuture<Void> defaultResponse = CompletableFuture.completedFuture(null);
private static final List<BookieId> ensemble = Collections.unmodifiableList(Lists.newArrayList(
Expand All @@ -88,8 +88,8 @@ public static Collection<BookieId> getMockEnsemble() {
return ensemble;
}

Queue<Long> addEntryDelaysMillis = new ConcurrentLinkedQueue<>();
List<CompletableFuture<Void>> failures = new ArrayList<>();
final Queue<Long> addEntryDelaysMillis = new ConcurrentLinkedQueue<>();
final List<CompletableFuture<Void>> failures = new ArrayList<>();

public PulsarMockBookKeeper(OrderedExecutor orderedExecutor) throws Exception {
this.orderedExecutor = orderedExecutor;
Expand Down Expand Up @@ -120,7 +120,8 @@ public void asyncCreateLedger(int ensSize, int writeQuorumSize, int ackQuorumSiz
try {
long id = sequence.getAndIncrement();
log.info("Creating ledger {}", id);
PulsarMockLedgerHandle lh = new PulsarMockLedgerHandle(PulsarMockBookKeeper.this, id, digestType, passwd);
PulsarMockLedgerHandle lh =
new PulsarMockLedgerHandle(PulsarMockBookKeeper.this, id, digestType, passwd);
ledgers.put(id, lh);
return FutureUtils.value(lh);
} catch (Throwable t) {
Expand Down Expand Up @@ -303,7 +304,7 @@ void checkProgrammedFail() throws BKException, InterruptedException {
getProgrammedFailure().get();
} catch (ExecutionException ee) {
if (ee.getCause() instanceof BKException) {
throw (BKException)ee.getCause();
throw (BKException) ee.getCause();
} else {
throw new BKException.BKUnexpectedConditionException();
}
Expand Down Expand Up @@ -331,7 +332,7 @@ public void failAfter(int steps, int rc) {
private int emptyLedgerAfter = -1;

/**
* After N times, make a ledger to appear to be empty
* After N times, make a ledger to appear to be empty.
*/
public synchronized void returnEmptyLedgerAfter(int steps) {
emptyLedgerAfter = steps;
Expand Down Expand Up @@ -373,12 +374,12 @@ public CompletableFuture<Versioned<Set<BookieId>>> getWritableBookies() {

@Override
public CompletableFuture<Versioned<Set<BookieId>>> getAllBookies() {
return CompletableFuture.completedFuture(new Versioned<Set<BookieId>>(new HashSet<>(ensemble), new LongVersion(0)));
return CompletableFuture.completedFuture(new Versioned<>(new HashSet<>(ensemble), new LongVersion(0)));
}

@Override
public CompletableFuture<Versioned<Set<BookieId>>> getReadOnlyBookies() {
return CompletableFuture.completedFuture(new Versioned<Set<BookieId>>(new HashSet<>(), new LongVersion(0)));
return CompletableFuture.completedFuture(new Versioned<>(new HashSet<>(), new LongVersion(0)));
}

@Override
Expand All @@ -404,7 +405,8 @@ public void unwatchReadOnlyBookies(RegistrationListener listener) {

private final MetadataClientDriver metadataClientDriver = new MetadataClientDriver() {
@Override
public MetadataClientDriver initialize(ClientConfiguration conf, ScheduledExecutorService scheduler, StatsLogger statsLogger, Optional<Object> ctx) throws MetadataException {
public MetadataClientDriver initialize(ClientConfiguration conf, ScheduledExecutorService scheduler,
StatsLogger statsLogger, Optional<Object> ctx) throws MetadataException {
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@
package org.apache.bookkeeper.client;

import com.google.common.collect.Lists;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;

import java.security.GeneralSecurityException;
import java.util.ArrayDeque;
import java.util.ArrayList;
Expand All @@ -31,7 +29,6 @@
import java.util.List;
import java.util.Queue;
import java.util.concurrent.CompletableFuture;

import org.apache.bookkeeper.client.AsyncCallback.AddCallback;
import org.apache.bookkeeper.client.AsyncCallback.CloseCallback;
import org.apache.bookkeeper.client.AsyncCallback.ReadCallback;
Expand Down Expand Up @@ -78,23 +75,23 @@ public PulsarMockLedgerHandle(PulsarMockBookKeeper bk, long id,
@Override
public void asyncClose(CloseCallback cb, Object ctx) {
bk.getProgrammedFailure().thenComposeAsync((res) -> {
fenced = true;

Versioned<LedgerMetadata> current = getVersionedLedgerMetadata();
Versioned<LedgerMetadata> newMetadata = new Versioned<>(
LedgerMetadataBuilder.from(current.getValue())
.withClosedState().withLastEntryId(getLastAddConfirmed())
.withLength(getLength()).build(),
new LongVersion(((LongVersion)current.getVersion()).getLongVersion() + 1));
setLedgerMetadata(current, newMetadata);
return FutureUtils.value(null);
}, bk.executor).whenCompleteAsync((res, exception) -> {
if (exception != null) {
cb.closeComplete(PulsarMockBookKeeper.getExceptionCode(exception), null, ctx);
} else {
cb.closeComplete(BKException.Code.OK, this, ctx);
}
}, bk.executor);
fenced = true;

Versioned<LedgerMetadata> current = getVersionedLedgerMetadata();
Versioned<LedgerMetadata> newMetadata = new Versioned<>(
LedgerMetadataBuilder.from(current.getValue())
.withClosedState().withLastEntryId(getLastAddConfirmed())
.withLength(getLength()).build(),
new LongVersion(((LongVersion) current.getVersion()).getLongVersion() + 1));
setLedgerMetadata(current, newMetadata);
return FutureUtils.value(null);
}, bk.executor).whenCompleteAsync((res, exception) -> {
if (exception != null) {
cb.closeComplete(PulsarMockBookKeeper.getExceptionCode(exception), null, ctx);
} else {
cb.closeComplete(BKException.Code.OK, this, ctx);
}
}, bk.executor);
}

@Override
Expand Down Expand Up @@ -128,7 +125,8 @@ public LedgerEntry nextElement() {
return FutureUtils.value(entries);
}).whenCompleteAsync((res, exception) -> {
if (exception != null) {
cb.readComplete(PulsarMockBookKeeper.getExceptionCode(exception), PulsarMockLedgerHandle.this, null, ctx);
cb.readComplete(PulsarMockBookKeeper.getExceptionCode(exception),
PulsarMockLedgerHandle.this, null, ctx);
} else {
cb.readComplete(BKException.Code.OK, PulsarMockLedgerHandle.this, res, ctx);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ class PulsarMockReadHandle implements ReadHandle {
private final LedgerMetadata metadata;
private final List<LedgerEntryImpl> entries;

PulsarMockReadHandle(PulsarMockBookKeeper bk, long ledgerId, LedgerMetadata metadata, List<LedgerEntryImpl> entries) {
PulsarMockReadHandle(PulsarMockBookKeeper bk, long ledgerId, LedgerMetadata metadata,
List<LedgerEntryImpl> entries) {
this.bk = bk;
this.ledgerId = ledgerId;
this.metadata = metadata;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* 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.bookkeeper.client;
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import org.objenesis.instantiator.ObjectInstantiator;

/**
* mock zookeeper with different session based on {@link MockZooKeeper}
* mock zookeeper with different session based on {@link MockZooKeeper}.
*/
public class MockZooKeeperSession extends ZooKeeper {

Expand Down Expand Up @@ -250,8 +250,6 @@ public long getSessionId() {

@Override
public String toString() {
return "MockZooKeeperSession{" +
"sessionId=" + sessionId +
'}';
return "MockZooKeeperSession{" + "sessionId=" + sessionId + '}';
}
}
19 changes: 19 additions & 0 deletions testmocks/src/main/java/org/apache/zookeeper/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* 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.zookeeper;

0 comments on commit 8319e8a

Please sign in to comment.