Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
7 changes: 5 additions & 2 deletions .kokoro/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@

set -eo pipefail

cd github/google-cloud-java/
## Get the directory of the build script
scriptDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
## cd to the parent directory, i.e. the root of the git repo
cd ${scriptDir}/..

function client_has_changes() {
CLIENT_NAME=$1
Expand Down Expand Up @@ -58,7 +61,7 @@ mvn install -B -V \
-T 1C

# prepend Kokoro root directory onto GOOGLE_APPLICATION_CREDENTIALS path
if [[ ! -z "${GOOGLE_APPLICATION_CREDENTIALS}" ]]; then
if [[ ! -z "${GOOGLE_APPLICATION_CREDENTIALS}" && "${GOOGLE_APPLICATION_CREDENTIALS}" != /* ]]; then
export GOOGLE_APPLICATION_CREDENTIALS=$(realpath ${KOKORO_ROOT}/src/${GOOGLE_APPLICATION_CREDENTIALS})
fi

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.google.cloud.firestore.it;

import static com.google.cloud.firestore.LocalFirestoreHelper.map;
import static com.google.common.collect.Sets.newHashSet;
import static java.util.Arrays.asList;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
Expand Down Expand Up @@ -52,17 +53,22 @@
import com.google.cloud.firestore.Transaction.Function;
import com.google.cloud.firestore.WriteBatch;
import com.google.cloud.firestore.WriteResult;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Sets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import javax.annotation.Nullable;
import org.junit.After;
Expand Down Expand Up @@ -886,6 +892,11 @@ public void queryWatch() throws Exception {
final Semaphore semaphore = new Semaphore(0);
ListenerRegistration registration = null;

final Set<String> expectedEvents =
Sets.newTreeSet(
newHashSet("event 0", "event 1", "event 2", "event 3", "event 4", "event 5"));
final Set<String> actualEvents = Collections.synchronizedSet(new TreeSet<String>());

try {
registration =
randomColl
Expand All @@ -898,39 +909,46 @@ public void queryWatch() throws Exception {
@Override
public void onEvent(
@Nullable QuerySnapshot value, @Nullable FirestoreException error) {
System.out.printf("onEvent(value : %s, error : %s)%n", value, error);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: is this intentionally left here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I'm wanting to see the events flowing in vs the switch branches below being hit. I haven't yet ruled out if there is some sort of race happening on the events being delivered.

try {
switch (semaphore.availablePermits()) {
case 0:
actualEvents.add("event 0");
assertTrue(value.isEmpty());
ref1 = randomColl.add(map("foo", "foo")).get();
ref2 = randomColl.add(map("foo", "bar")).get();
break;
case 1:
actualEvents.add("event 1");
assertEquals(1, value.size());
assertEquals(1, value.getDocumentChanges().size());
assertEquals(Type.ADDED, value.getDocumentChanges().get(0).getType());
ref1.set(map("foo", "bar"));
break;
case 2:
actualEvents.add("event 2");
assertEquals(2, value.size());
assertEquals(1, value.getDocumentChanges().size());
assertEquals(Type.ADDED, value.getDocumentChanges().get(0).getType());
ref1.set(map("foo", "bar", "bar", " foo"));
break;
case 3:
actualEvents.add("event 3");
assertEquals(2, value.size());
assertEquals(1, value.getDocumentChanges().size());
assertEquals(
Type.MODIFIED, value.getDocumentChanges().get(0).getType());
ref2.set(map("foo", "foo"));
break;
case 4:
actualEvents.add("event 4");
assertEquals(1, value.size());
assertEquals(1, value.getDocumentChanges().size());
assertEquals(Type.REMOVED, value.getDocumentChanges().get(0).getType());
ref1.delete();
break;
case 5:
actualEvents.add("event 5");
assertTrue(value.isEmpty());
assertEquals(1, value.getDocumentChanges().size());
assertEquals(Type.REMOVED, value.getDocumentChanges().get(0).getType());
Expand All @@ -943,7 +961,18 @@ public void onEvent(
}
});

semaphore.acquire(6);
final boolean tryAcquire = semaphore.tryAcquire(6, 60, TimeUnit.SECONDS);

final Joiner j = Joiner.on(", ");
final String expectedString = j.join(expectedEvents);
final String actualString = j.join(actualEvents);
assertTrue(
String.format(
"did not receive all expected events within the deadline.%n"
+ "expectedEvents = [%s]%n"
+ " actualEvents = [%s]%n",
expectedString, actualString),
tryAcquire);
} finally {
if (registration != null) {
registration.remove();
Expand Down