Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored SentinelGrpcServerInterceptorTest #101

Merged
Changes from 1 commit
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
Next Next commit
Refactored some classes
talshalti committed Aug 28, 2018

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit cef77460114ad70c9d58064641afeb9bbe4e1072
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.alibaba.csp.sentinel.adapter.grpc;

import io.grpc.Server;
import io.grpc.ServerBuilder;

import java.io.IOException;

import static org.junit.Assert.*;

class ExtractedSentinelGrpcClientInterceptorTest {
private Server server;

ExtractedSentinelGrpcClientInterceptorTest() {
}

void prepareServer(int port) throws IOException {
if (server != null) {
throw new IllegalStateException("Server already running!");
}
server = ServerBuilder.forPort(port)
.addService(new FooServiceImpl())
.build();
server.start();
}

void stopServer() {
if (server != null) {
server.shutdown();
server = null;
}
}
}
Original file line number Diff line number Diff line change
@@ -43,8 +43,7 @@ public class SentinelGrpcClientInterceptorTest {

private final String resourceName = "com.alibaba.sentinel.examples.FooService/sayHello";
private final int threshold = 2;

private Server server;
private final ExtractedSentinelGrpcClientInterceptorTest extractedSentinelGrpcClientInterceptorTest = new ExtractedSentinelGrpcClientInterceptorTest();

private void configureFlowRule() {
FlowRule rule = new FlowRule()
@@ -61,7 +60,7 @@ public void testGrpcClientInterceptor() throws Exception {
final int port = 19328;

configureFlowRule();
prepareServer(port);
extractedSentinelGrpcClientInterceptorTest.prepareServer(port);

FooServiceClient client = new FooServiceClient("localhost", port, new SentinelGrpcClientInterceptor());
final int total = 8;
@@ -81,7 +80,7 @@ public void testGrpcClientInterceptor() throws Exception {
assertEquals(total - threshold, blockedQps);
assertEquals(threshold, passQps);

stopServer();
extractedSentinelGrpcClientInterceptorTest.stopServer();
}

private void sendRequest(FooServiceClient client) {
@@ -94,20 +93,4 @@ private void sendRequest(FooServiceClient client) {
}
}

private void prepareServer(int port) throws IOException {
if (server != null) {
throw new IllegalStateException("Server already running!");
}
server = ServerBuilder.forPort(port)
.addService(new FooServiceImpl())
.build();
server.start();
}

private void stopServer() {
if (server != null) {
server.shutdown();
server = null;
}
}
}