Skip to content
Permalink
Browse files
add server send big header test
  • Loading branch information
EarthChen committed Sep 13, 2021
1 parent fa513af commit 22d3e657ea00ea1066f46994ec98ee43c5154a41
Showing 3 changed files with 25 additions and 5 deletions.
@@ -6,7 +6,6 @@
import org.apache.dubbo.sample.tri.service.PbGreeterManual;

import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;

import java.util.concurrent.CountDownLatch;
@@ -70,16 +69,23 @@ public void unaryGreeter() {


@Test(expected = RpcException.class)
@Ignore
public void clientSendLargeSizeHeader() {
StringBuilder sb = new StringBuilder("a");
for (int j = 0; j < 15; j++) {
sb.append(sb);
}
sb.setLength(8191);
sb.setLength(8000);
RpcContext.getClientAttachment().setObjectAttachment("large-size-meta", sb.toString());
delegate.greet(GreeterRequest.newBuilder().setName("meta").build());
RpcContext.getClientAttachment().clearAttachments();
}


@Test(expected = RpcException.class)
public void serverSendLargeSizeHeader() {
final String key = "user-attachment";
GreeterReply reply = delegateManual.greetReturnBigAttachment(GreeterRequest.newBuilder().setName("meta").build());
final String returned = (String) RpcContext.getServerContext().getObjectAttachment(key);
Assert.assertNotNull(returned);
}

@Test
@@ -9,6 +9,8 @@
public interface PbGreeterManual {

GreeterReply greetWithAttachment(GreeterRequest request);

GreeterReply greetReturnBigAttachment(GreeterRequest request);
//
// GreeterReply greet(GreeterRequest request);

@@ -12,7 +12,19 @@ public class PbGreeterImpl implements PbGreeter, PbGreeterManual {
@Override
public GreeterReply greetWithAttachment(GreeterRequest request) {
final String key = "user-attachment";
final String value = "hello,"+RpcContext.getServerAttachment().getAttachment(key);
final String value = "hello," + RpcContext.getServerAttachment().getAttachment(key);
RpcContext.getServerContext().setObjectAttachment(key, value);
return GreeterReply.newBuilder().setMessage("hello," + request.getName()).build();
}

@Override
public GreeterReply greetReturnBigAttachment(GreeterRequest request) {
final String key = "user-attachment";
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < 8000; i++) {
stringBuilder.append(i);
}
String value = stringBuilder.toString();
RpcContext.getServerContext().setObjectAttachment(key, value);
return GreeterReply.newBuilder().setMessage("hello," + request.getName()).build();
}

0 comments on commit 22d3e65

Please sign in to comment.