Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
schmidt-sebastian committed Jun 24, 2021
1 parent fc77332 commit f2c76a1
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 100 deletions.
Expand Up @@ -447,7 +447,7 @@ public FirestoreOptions getOptions() {

@Override
public void close() throws Exception {
shutdown();
shutdown();
}

@Override
Expand Down
Expand Up @@ -388,7 +388,7 @@ public void limitToLast() throws Exception {
public void shutdownNowRejectsListener() throws Exception {
Query query = randomColl.whereEqualTo("foo", "bar");
QuerySnapshotEventListener listener =
QuerySnapshotEventListener.builder().setExpectError().build();
QuerySnapshotEventListener.builder().setExpectError().build();

query.addSnapshotListener(listener);
firestore.shutdownNow();
Expand All @@ -403,7 +403,7 @@ public void shutdownNowRejectsListener() throws Exception {
public void shutdownNowPreventsListener() throws Exception {
Query query = randomColl.whereEqualTo("foo", "bar");
QuerySnapshotEventListener listener =
QuerySnapshotEventListener.builder().setExpectError().build();
QuerySnapshotEventListener.builder().setExpectError().build();

firestore.shutdownNow();
query.addSnapshotListener(listener);
Expand Down
Expand Up @@ -6,106 +6,121 @@
import com.google.cloud.firestore.FirestoreOptions;
import com.google.cloud.firestore.ListenerRegistration;
import com.google.cloud.firestore.QuerySnapshot;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.Timeout;

import javax.annotation.Nullable;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

public class ITShutdownTest {
@Rule
public final Timeout timeout = new Timeout(5, TimeUnit.SECONDS);

@Test
public void closeSuccess_withListenerRemove() throws Exception {

final CountDownLatch cdl = new CountDownLatch(1);

Firestore fs = FirestoreOptions.getDefaultInstance().getService();
ListenerRegistration listener = fs.collection("abcd").addSnapshotListener(new EventListener<QuerySnapshot>() {
@Override
public void onEvent(@Nullable QuerySnapshot value, @Nullable FirestoreException error) {
cdl.countDown();
}
});


cdl.await();
listener.remove();
fs.close();
}

@Test
public void closeSuccess_withoutListenerRemove() throws Exception {

final CountDownLatch cdl = new CountDownLatch(1);

Firestore fs = FirestoreOptions.getDefaultInstance().getService();
ListenerRegistration listener = fs.collection("abcd").addSnapshotListener(new EventListener<QuerySnapshot>() {
@Override
public void onEvent(@Nullable QuerySnapshot value, @Nullable FirestoreException error) {
cdl.countDown();
}
});

cdl.await();
fs.close();
}

@Test
public void shutdownNowSuccess_withoutListenerRemove() throws Exception {

final CountDownLatch cdl = new CountDownLatch(1);

Firestore fs = FirestoreOptions.getDefaultInstance().getService();
ListenerRegistration listener = fs.collection("abcd").addSnapshotListener(new EventListener<QuerySnapshot>() {
@Override
public void onEvent(@Nullable QuerySnapshot value, @Nullable FirestoreException error) {
cdl.countDown();
}
});


cdl.await();
fs.shutdownNow();
}

@Test
public void shutdownSuccess_withoutListenerRemove() throws Exception {

final CountDownLatch cdl = new CountDownLatch(1);

Firestore fs = FirestoreOptions.getDefaultInstance().getService();
ListenerRegistration listener = fs.collection("abcd").addSnapshotListener(new EventListener<QuerySnapshot>() {
@Override
public void onEvent(@Nullable QuerySnapshot value, @Nullable FirestoreException error) {
cdl.countDown();
}
});

cdl.await();
fs.shutdown();
}

@Test
public void closeAndShutdown() throws Exception {

final CountDownLatch cdl = new CountDownLatch(1);

Firestore fs = FirestoreOptions.getDefaultInstance().getService();
ListenerRegistration listener = fs.collection("abcd").addSnapshotListener(new EventListener<QuerySnapshot>() {
@Override
public void onEvent(@Nullable QuerySnapshot value, @Nullable FirestoreException error) {
cdl.countDown();
}
});


cdl.await();
fs.close();
fs.shutdown();
fs.shutdownNow();
}
@Rule public final Timeout timeout = new Timeout(5, TimeUnit.SECONDS);

@Test
public void closeSuccess_withListenerRemove() throws Exception {

final CountDownLatch cdl = new CountDownLatch(1);

Firestore fs = FirestoreOptions.getDefaultInstance().getService();
ListenerRegistration listener =
fs.collection("abcd")
.addSnapshotListener(
new EventListener<QuerySnapshot>() {
@Override
public void onEvent(
@Nullable QuerySnapshot value, @Nullable FirestoreException error) {
cdl.countDown();
}
});

cdl.await();
listener.remove();
fs.close();
}

@Test
public void closeSuccess_withoutListenerRemove() throws Exception {

final CountDownLatch cdl = new CountDownLatch(1);

Firestore fs = FirestoreOptions.getDefaultInstance().getService();
ListenerRegistration listener =
fs.collection("abcd")
.addSnapshotListener(
new EventListener<QuerySnapshot>() {
@Override
public void onEvent(
@Nullable QuerySnapshot value, @Nullable FirestoreException error) {
cdl.countDown();
}
});

cdl.await();
fs.close();
}

@Test
public void shutdownNowSuccess_withoutListenerRemove() throws Exception {

final CountDownLatch cdl = new CountDownLatch(1);

Firestore fs = FirestoreOptions.getDefaultInstance().getService();
ListenerRegistration listener =
fs.collection("abcd")
.addSnapshotListener(
new EventListener<QuerySnapshot>() {
@Override
public void onEvent(
@Nullable QuerySnapshot value, @Nullable FirestoreException error) {
cdl.countDown();
}
});

cdl.await();
fs.shutdownNow();
}

@Test
public void shutdownSuccess_withoutListenerRemove() throws Exception {

final CountDownLatch cdl = new CountDownLatch(1);

Firestore fs = FirestoreOptions.getDefaultInstance().getService();
ListenerRegistration listener =
fs.collection("abcd")
.addSnapshotListener(
new EventListener<QuerySnapshot>() {
@Override
public void onEvent(
@Nullable QuerySnapshot value, @Nullable FirestoreException error) {
cdl.countDown();
}
});

cdl.await();
fs.shutdown();
}

@Test
public void closeAndShutdown() throws Exception {

final CountDownLatch cdl = new CountDownLatch(1);

Firestore fs = FirestoreOptions.getDefaultInstance().getService();
ListenerRegistration listener =
fs.collection("abcd")
.addSnapshotListener(
new EventListener<QuerySnapshot>() {
@Override
public void onEvent(
@Nullable QuerySnapshot value, @Nullable FirestoreException error) {
cdl.countDown();
}
});

cdl.await();
fs.close();
fs.shutdown();
fs.shutdownNow();
}
}

0 comments on commit f2c76a1

Please sign in to comment.