@Test(timeout=60000)
public void testServerSideThrottle() throws Exception {
int messageWindowSize = DEFAULT_MESSAGE_WINDOW_SIZE;
ThrottleDeliveryClientConfiguration conf =
new ThrottleDeliveryClientConfiguration();
HedwigClient client = new HedwigClient(conf);
Publisher pub = client.getPublisher();
Subscriber sub = client.getSubscriber();
ByteString topic = ByteString.copyFromUtf8("testServerSideThrottle");
ByteString subid = ByteString.copyFromUtf8("serverThrottleSub");
sub.subscribe(topic, subid, CreateOrAttach.CREATE);
sub.closeSubscription(topic, subid);
// throttle with hub server's setting
throttleX(pub, sub, topic, subid, DEFAULT_MESSAGE_WINDOW_SIZE);
messageWindowSize = DEFAULT_MESSAGE_WINDOW_SIZE / 2;
// throttle with a lower value than hub server's setting
SubscriptionOptions.Builder optionsBuilder = SubscriptionOptions.newBuilder()
.setCreateOrAttach(CreateOrAttach.CREATE)
.setMessageWindowSize(messageWindowSize);
topic = ByteString.copyFromUtf8("testServerSideThrottleWithLowerValue");
sub.subscribe(topic, subid, optionsBuilder.build());
sub.closeSubscription(topic, subid);
throttleX(pub, sub, topic, subid, messageWindowSize);
messageWindowSize = DEFAULT_MESSAGE_WINDOW_SIZE + 5;
// throttle with a higher value than hub server's setting
optionsBuilder = SubscriptionOptions.newBuilder()
.setCreateOrAttach(CreateOrAttach.CREATE)
.setMessageWindowSize(messageWindowSize);
topic = ByteString.copyFromUtf8("testServerSideThrottleWithHigherValue");
sub.subscribe(topic, subid, optionsBuilder.build());
sub.closeSubscription(topic, subid);
throttleX(pub, sub, topic, subid, messageWindowSize);
client.close();
}