Skip to content

Commit

Permalink
Fix some lints. (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
slinkydeveloper authored Oct 27, 2023
1 parent 0ee6f08 commit 5780a3f
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 15 deletions.
7 changes: 7 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ subprojects {
sourceCompatibility = "11"

options.errorprone.disableWarningsInGeneratedCode.set(true)
options.errorprone.disable(
// We use toString() in proto messages for debugging reasons.
"LiteProtoToString",
// This check is proposing to use a guava API instead...
"StringSplitter",
// This is conflicting with a javadoc warn lint
"MissingSummary")
options.errorprone.excludedPaths.set(".*/build/generated/.*")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public int getLength() {

public long encode() {
long res = 0L;
res |= ((long) (type.encode()) << 48);
res |= ((long) (flags) << 32);
res |= ((long) type.encode() << 48);
res |= ((long) flags << 32);
res |= length;
return res;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class ProtocolException extends RuntimeException {
static final int JOURNAL_MISMATCH_CODE = 32;
static final int PROTOCOL_VIOLATION = 33;

@SuppressWarnings("StaticAssignmentOfThrowable")
static final ProtocolException CLOSED = new ProtocolException("Invocation closed");

private final int failureCode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ void onNewReadyResult(OnNewReadyResultCallback callback) {
this.tryProgress(callback);
}

@Override
void abort(Throwable cause) {
super.abort(cause);
this.consumeCallback(this::tryProgress);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public void exitSideEffectBlockWithException(

// If it's a non-terminal exception (such as a protocol exception),
// we don't write it but simply throw it
if (!(isTerminalException(toWrite))) {
if (!isTerminalException(toWrite)) {
// For safety wrt Syscalls API we do this check and wrapping,
// but with the current APIs the exception should always be RuntimeException
// because that's what can be thrown inside a lambda
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,21 @@ public BufferedMockPublisher(Collection<T> elements) {
@Override
public void subscribe(Flow.Subscriber<? super T> subscriber) {
subscriber.onSubscribe(
new MockSubscription<>(subscriber, new ArrayDeque<>(elements), subscriptionCancelled));
new BufferedMockSubscription<>(
subscriber, new ArrayDeque<>(elements), subscriptionCancelled));
}

public boolean isSubscriptionCancelled() {
return subscriptionCancelled.get();
}

private static class MockSubscription<T> implements Flow.Subscription {
private static class BufferedMockSubscription<T> implements Flow.Subscription {

private final Flow.Subscriber<? super T> subscriber;
private final Queue<T> queue;
private final AtomicBoolean cancelled;

private MockSubscription(
private BufferedMockSubscription(
Flow.Subscriber<? super T> subscriber,
Queue<T> queue,
AtomicBoolean subscriptionCancelled) {
Expand Down Expand Up @@ -105,11 +106,11 @@ public void cancel() {

public static class UnbufferedMockPublisher<T> implements Flow.Publisher<T> {

private MockSubscription<T> subscription;
private UnbufferedMockSubscription<T> subscription;

@Override
public void subscribe(Flow.Subscriber<? super T> subscriber) {
this.subscription = new MockSubscription<>(subscriber);
this.subscription = new UnbufferedMockSubscription<>(subscriber);
subscriber.onSubscribe(this.subscription);
}

Expand All @@ -125,15 +126,15 @@ public void close() {
Objects.requireNonNull(this.subscription).onClose();
}

private static class MockSubscription<T> implements Flow.Subscription {
private static class UnbufferedMockSubscription<T> implements Flow.Subscription {

private final Flow.Subscriber<? super T> subscriber;
private final Queue<T> queue;
private boolean publisherClosed = false;
private long request = 0;
private boolean cancelled = false;

private MockSubscription(Flow.Subscriber<? super T> subscriber) {
private UnbufferedMockSubscription(Flow.Subscriber<? super T> subscriber) {
this.subscriber = subscriber;
this.queue = new ArrayDeque<>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public static class WithInputBuilder extends TestInvocationBuilder {
this.input = new ArrayList<>(input);
}

@Override
public WithInputBuilder withInput(MessageLiteOrBuilder... messages) {
if (this.invalidReason == null) {
this.input.addAll(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@
*/
public interface InvocationId {

/** gRPC {@link Context} key for invocation id. */
Context.Key<InvocationId> INVOCATION_ID_KEY = Context.key("restate.dev/service_invocation_id");

/** Retrieves the current invocation id from the current gRPC {@link Context}. */
/**
* @return the current invocation id from the current gRPC {@link Context}.
*/
static InvocationId current() {
return INVOCATION_ID_KEY.get();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ public interface DeferredResult<T> {

boolean isCompleted();

/** Null if {@link #isCompleted()} is false. */
/**
* @return {@code null} if {@link #isCompleted()} is false.
*/
@Nullable
ReadyResult<T> toReadyResult();
}
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ private Executor blockingExecutor(String serviceName, Context currentContext) {

private void handleDiscoveryRequest(HttpServerRequest request) {
// Request validation
if (request.method() != HttpMethod.POST) {
if (!request.method().equals(HttpMethod.POST)) {
request.response().setStatusCode(METHOD_NOT_ALLOWED.code()).end();
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public void greet(GreetingRequest request, StreamObserver<GreetingResponse> resp
}
}

@Override
protected BindableService returnAwakeableId() {
return new ReturnAwakeableId();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ private static class SleepGreeter extends GreeterGrpc.GreeterImplBase
public void greet(GreetingRequest request, StreamObserver<GreetingResponse> responseObserver) {
RestateContext ctx = restateContext();

ctx.sleep(Duration.ofMillis(1000));
ctx.sleep(Duration.ofSeconds(1));

responseObserver.onNext(GreetingResponse.newBuilder().setMessage("Hello").build());
responseObserver.onCompleted();
Expand All @@ -40,7 +40,7 @@ public void greet(GreetingRequest request, StreamObserver<GreetingResponse> resp
List<Awaitable<?>> collectedAwaitables = new ArrayList<>();

for (int i = 0; i < 10; i++) {
collectedAwaitables.add(ctx.timer(Duration.ofMillis(1000)));
collectedAwaitables.add(ctx.timer(Duration.ofSeconds(1)));
}

Awaitable.all(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ private void handle(
serviceInvocationStateMachineHandler.start();
}

@SuppressWarnings("unchecked")
private Object extractKey(
String serviceName, String methodName, Protocol.PollInputStreamEntryMessage message) {
LOG.debug("Extracting key for service {} and method {}", serviceName, methodName);
Expand Down Expand Up @@ -392,6 +393,7 @@ private void routeMessage(MessageLite t) {
}
}

@SuppressWarnings("FutureReturnValueIgnored")
public void handleInvokeEntryMessage(Protocol.InvokeEntryMessage msg) {
String invocationId = UUID.randomUUID().toString();
CompletableFuture<? super MessageLite> future = new CompletableFuture<>();
Expand All @@ -417,6 +419,7 @@ public void handleInvokeEntryMessage(Protocol.InvokeEntryMessage msg) {
Protocol.PollInputStreamEntryMessage.newBuilder().setValue(msg.getParameter()).build());
}

@SuppressWarnings("FutureReturnValueIgnored")
public void handleAwakeableEntryMessage() {
CompletableFuture<? super MessageLite> future = new CompletableFuture<>();
future.handle(
Expand Down

0 comments on commit 5780a3f

Please sign in to comment.