-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support user-provided gRPC client interceptors.
- Loading branch information
Showing
5 changed files
with
77 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
db-client-java/src/test/java/com/eventstore/dbclient/InterceptorTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.eventstore.dbclient; | ||
|
||
import io.grpc.*; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import testcontainers.module.ESDBTests; | ||
|
||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
public class InterceptorTests extends ESDBTests { | ||
@Test | ||
public void testInterceptorIsCalled() { | ||
EventStoreDBClientSettings settings = getEmptyServer().getSettings(); | ||
|
||
AtomicInteger atom = new AtomicInteger(0); | ||
|
||
settings.getInterceptors().add(new MyInterceptor(atom)); | ||
|
||
EventStoreDBClient client = EventStoreDBClient.create(settings); | ||
try { | ||
client.readStream("foobar", ReadStreamOptions.get()).get(); | ||
} catch (Exception e) { | ||
// We don't care. | ||
} | ||
|
||
Assertions.assertEquals(42, atom.get()); | ||
} | ||
|
||
class MyInterceptor implements ClientInterceptor { | ||
final AtomicInteger atom; | ||
|
||
MyInterceptor(AtomicInteger atom) { | ||
this.atom = atom; | ||
} | ||
@Override | ||
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, Channel next) { | ||
atom.set(42); | ||
return next.newCall(method, callOptions); | ||
} | ||
} | ||
} |