Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions api/src/testFixtures/java/io/grpc/testing/StatusSubject.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright 2026 The gRPC Authors
*
* Licensed 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 io.grpc.testing;

import static com.google.common.truth.Fact.fact;

import com.google.common.truth.FailureMetadata;
import com.google.common.truth.Subject;
import io.grpc.Status;
import javax.annotation.Nullable;

/** Propositions for {@link Status} subjects. */
public final class StatusSubject extends Subject {

private static final Subject.Factory<StatusSubject, Status> statusFactory = new Factory();

public static Subject.Factory<StatusSubject, Status> status() {
return statusFactory;
}

private final Status actual;

private StatusSubject(FailureMetadata metadata, @Nullable Status subject) {
super(metadata, subject);
this.actual = subject;
}

/** Fails if the subject is not OK. */
public void isOk() {
if (actual == null) {
failWithActual("expected to be OK but was", "null");
} else if (!actual.isOk()) {
failWithoutActual(
fact("expected to be OK but was", actual.getCode()),
fact("description", actual.getDescription()),
fact("cause", actual.getCause()));
}
}

/** Fails if the subject does not have the given code. */
public void hasCode(Status.Code expectedCode) {
if (actual == null) {
failWithActual("expected to have code " + expectedCode + " but was", "null");
} else {
check("getCode()").that(actual.getCode()).isEqualTo(expectedCode);
}
}

private static final class Factory implements Subject.Factory<StatusSubject, Status> {
@Override
public StatusSubject createSubject(FailureMetadata metadata, @Nullable Status that) {
return new StatusSubject(metadata, that);
}
}
}
1 change: 1 addition & 0 deletions binder/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ dependencies {
testImplementation project(':grpc-testing')
testImplementation project(':grpc-inprocess')
testImplementation testFixtures(project(':grpc-core'))
testImplementation testFixtures(project(':grpc-api'))

androidTestAnnotationProcessor libraries.auto.value
androidTestImplementation project(':grpc-testing')
Expand Down
19 changes: 18 additions & 1 deletion binder/src/main/java/io/grpc/binder/internal/BinderServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public final class BinderServer implements InternalServer, LeakSafeOneWayBinder.
private final LeakSafeOneWayBinder hostServiceBinder;
private final BinderTransportSecurity.ServerPolicyChecker serverPolicyChecker;
private final InboundParcelablePolicy inboundParcelablePolicy;
private final OneWayBinderProxy.Decorator clientBinderDecorator;

@GuardedBy("this")
private ServerListener listener;
Expand All @@ -92,6 +93,7 @@ private BinderServer(Builder builder) {
ImmutableList.copyOf(checkNotNull(builder.streamTracerFactories, "streamTracerFactories"));
this.serverPolicyChecker = BinderInternal.createPolicyChecker(builder.serverSecurityPolicy);
this.inboundParcelablePolicy = builder.inboundParcelablePolicy;
this.clientBinderDecorator = builder.clientBinderDecorator;
hostServiceBinder = new LeakSafeOneWayBinder(this);
}

Expand Down Expand Up @@ -183,7 +185,7 @@ public synchronized boolean handleTransaction(int code, Parcel parcel) {
executorServicePool,
attrsBuilder.build(),
streamTracerFactories,
OneWayBinderProxy.IDENTITY_DECORATOR,
clientBinderDecorator,
callbackBinder);
transport.start(listener.transportCreated(transport));
return true;
Expand Down Expand Up @@ -225,6 +227,7 @@ public static class Builder {
SharedResourcePool.forResource(GrpcUtil.TIMER_SERVICE);
ServerSecurityPolicy serverSecurityPolicy = SecurityPolicies.serverInternalOnly();
InboundParcelablePolicy inboundParcelablePolicy = InboundParcelablePolicy.DEFAULT;
OneWayBinderProxy.Decorator clientBinderDecorator = OneWayBinderProxy.IDENTITY_DECORATOR;

public BinderServer build() {
return new BinderServer(this);
Expand Down Expand Up @@ -295,5 +298,19 @@ public Builder setInboundParcelablePolicy(InboundParcelablePolicy inboundParcela
checkNotNull(inboundParcelablePolicy, "inboundParcelablePolicy");
return this;
}

/**
* Sets the {@link OneWayBinderProxy.Decorator} to be applied to this server's "client Binders".
*
* <p>Tests can use this to capture post-setup transactions from server to client. The specified
* decorator will be applied every time a client connects. The decorated result will be used for
* all subsequent transactions to this client from the new ServerTransport.
*
* <p>Optional, {@link OneWayBinderProxy#IDENTITY_DECORATOR} is the default.
*/
public Builder setClientBinderDecorator(OneWayBinderProxy.Decorator clientBinderDecorator) {
this.clientBinderDecorator = checkNotNull(clientBinderDecorator);
return this;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ final class BlockPool {
* The size of each standard block. (Currently 16k) The block size must be at least as large as
* the maximum header list size.
*/
private static final int BLOCK_SIZE = Math.max(16 * 1024, GrpcUtil.DEFAULT_MAX_HEADER_LIST_SIZE);
static final int BLOCK_SIZE = Math.max(16 * 1024, GrpcUtil.DEFAULT_MAX_HEADER_LIST_SIZE);

/**
* Maximum number of blocks to keep around. (Max 128k). This limit is a judgement call. 128k is
Expand Down
Loading
Loading