Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -163,19 +163,20 @@ public Subscription executeBatch(final List<BatchTask> tasks, final Observer<Bat
return new Subscription() {
@Override
public void close() {
if (internalObserver.doRelease()) {
if (internalObserver.doRelease() && subscription != null) {
subscription.close();
}
}

@Override
public boolean isUnsubscribed() {
return internalObserver.isUnsubscribed() && subscription.isUnsubscribed();
return internalObserver.isUnsubscribed()
&& (subscription == null || subscription.isUnsubscribed());
}

@Override
public Object getReturnValue() {
return subscription.getReturnValue();
return subscription == null ? null : subscription.getReturnValue();
}
};
} catch (Throwable t) {
Expand All @@ -195,14 +196,15 @@ public Subscription queryBatch(final BatchToken token, final Observer<BatchResul
return new Subscription() {
@Override
public void close() {
if (internalObserver.doRelease()) {
if (internalObserver.doRelease() && subscription != null) {
subscription.close();
}
}

@Override
public boolean isUnsubscribed() {
return internalObserver.isUnsubscribed() && subscription.isUnsubscribed();
return internalObserver.isUnsubscribed()
&& (subscription == null || subscription.isUnsubscribed());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,20 +374,29 @@ public void onNext(BatchResult batchResult) {
};

final List<BatchTask> batchTasks = batch.build();
Subscription sub = facade.executeBatch(batchTasks, observer, options);
assertNotNull(sub.getReturnValue());
final Subscription sub = facade.executeBatch(batchTasks, observer, options);
try {
assertNotNull(sub.getReturnValue());

final long timeout = System.currentTimeMillis() + 3000;
while (!isComplete.get() && System.currentTimeMillis() < timeout) {
Thread.sleep(100);
}
final long timeout = System.currentTimeMillis() + 3000;
while (!isComplete.get() && System.currentTimeMillis() < timeout) {
Thread.sleep(100);
}

assertEquals(results.size(), batchTasks.size());
assertTrue(isComplete.get());
assertFalse(hasError.get());
assertEquals(results.size(), batchTasks.size());
assertTrue(isComplete.get());
assertFalse(hasError.get());

sub = facade.queryBatch((BatchToken) sub.getReturnValue(), observer, options);
assertNull(sub.getReturnValue());
final Subscription query = facade.queryBatch((BatchToken) sub.getReturnValue(), observer, options);
try {
assertNull(query.getReturnValue());
} finally {
query.close();
}
} finally {
// the subscription holds a pooled connector until it is closed
sub.close();
}
}

@Test
Expand Down Expand Up @@ -435,17 +444,22 @@ public void onNext(BatchResult batchResult) {
}
};

Subscription sub = facade.executeBatch(batch.build(), observer, options);
assertEquals(results.size(), 0);
assertFalse(isComplete.get());
assertFalse(hasError.get());
assertNotNull(sub.getReturnValue());
final Subscription sub = facade.executeBatch(batch.build(), observer, options);
try {
assertNotNull(sub.getReturnValue());

Thread.sleep(500);
final long timeout = System.currentTimeMillis() + 3000;
while (!hasError.get() && System.currentTimeMillis() < timeout) {
Thread.sleep(100);
}

assertEquals(results.size(), 2);
assertFalse(isComplete.get());
assertTrue(hasError.get());
assertEquals(results.size(), 2);
assertFalse(isComplete.get());
assertTrue(hasError.get());
} finally {
// the subscription holds a pooled connector until it is closed
sub.close();
}
}

@Test
Expand Down
Loading