// 300 subscribers subscribe to a same topic
final AtomicBoolean inRedirectLoop = new AtomicBoolean(false);
numDone.set(0);
for (int i=0; i<numSubscribers; i++) {
ByteString subId = ByteString.copyFromUtf8("sub-" + i);
if (logger.isDebugEnabled()) {
logger.debug("subscriber " + subId.toStringUtf8() + " subscribes topic " + topic.toStringUtf8());
}
subscriber.asyncSubscribe(topic, subId, CreateOrAttach.CREATE_OR_ATTACH,
new Callback<Void>() {
private void tick() {
if (numDone.incrementAndGet() == numSubscribers) {
ConcurrencyUtils.put(queue, true);
}
}
@Override
public void operationFinished(Object ctx,
Void resultOfOperation) {
tick();
}
@Override
public void operationFailed(Object ctx,
PubSubException exception) {
if (exception instanceof PubSubException.ServiceDownException) {
String msg = exception.getMessage();
if (msg.indexOf("ServerRedirectLoopException") > 0) {
inRedirectLoop.set(true);
}
if (logger.isDebugEnabled()) {
logger.debug("Operation failed : ", exception);
}
}
tick();
}
},
null);
}
queue.take();
// TODO: remove comment after we fix the issue
// Assert.assertEquals(false, inRedirectLoop.get());
// start a thread to send subscriptions
numDone.set(0);
Thread sub = new Thread(new Runnable() {
@Override
public void run() {
logger.info("sub thread started");
try {
// 100 subscribers subscribe to a same topic
for (int i=0; i<numSubscribers; i++) {
ByteString subscriberId = ByteString.copyFromUtf8("sub-" + i);
subscribers.put(subscriberId);
}
ByteString subId;
while (true) {
subId = subscribers.take();
if (logger.isDebugEnabled()) {
logger.debug("subscriber " + subId.toStringUtf8() + " subscribes topic " + topic.toStringUtf8());
}
subscriber.asyncSubscribe(topic, subId, CreateOrAttach.CREATE_OR_ATTACH,
new SubCallback(subId), null);
}
// subscriber.asyncSubscribe(topic, subscriberId, mode, callback, context)