Skip to content
Permalink
Browse files
fix: create filter in correct order (#180)
* fix: create filter in correct order

* tests: fix flaky test

* tests: fix another flaky test
  • Loading branch information
olavloite committed Apr 28, 2020
1 parent 060a81a commit d80428a5b0291516b2298e2309de09b23e4c387d
@@ -703,9 +703,9 @@ public Paginated<Operation> listOperations(String nextPageToken) {
instanceName,
0,
String.format(
"(name:%s/operations/) AND (metadata.@type:type.googleapis.com/%s)",
String.format("%s/databases/%s", instanceName, databaseId),
CreateDatabaseMetadata.getDescriptor().getFullName()),
"(metadata.@type:type.googleapis.com/%s) AND (name:%s/operations/)",
CreateDatabaseMetadata.getDescriptor().getFullName(),
String.format("%s/databases/%s", instanceName, databaseId)),
nextPageToken);
}
},
@@ -822,9 +822,9 @@ public Paginated<Operation> listOperations(String nextPageToken) {
instanceName,
0,
String.format(
"(metadata.name:%s) AND (metadata.@type:type.googleapis.com/%s)",
String.format("%s/backups/%s", instanceName, backupId),
CreateBackupMetadata.getDescriptor().getFullName()),
"(metadata.@type:type.googleapis.com/%s) AND (metadata.name:%s)",
CreateBackupMetadata.getDescriptor().getFullName(),
String.format("%s/backups/%s", instanceName, backupId)),
nextPageToken);
}
},
@@ -874,9 +874,9 @@ public Paginated<Operation> listOperations(String nextPageToken) {
databaseInstanceName,
0,
String.format(
"(metadata.name:%s) AND (metadata.@type:type.googleapis.com/%s)",
String.format("%s/databases/%s", databaseInstanceName, databaseId),
RestoreDatabaseMetadata.getDescriptor().getFullName()),
"(metadata.@type:type.googleapis.com/%s) AND (metadata.name:%s)",
RestoreDatabaseMetadata.getDescriptor().getFullName(),
String.format("%s/databases/%s", databaseInstanceName, databaseId)),
nextPageToken);
}
},
@@ -27,6 +27,7 @@
import com.google.cloud.spanner.admin.database.v1.MockDatabaseAdminImpl;
import com.google.common.base.Throwables;
import com.google.common.collect.Lists;
import com.google.common.util.concurrent.Uninterruptibles;
import com.google.protobuf.AbstractMessage;
import com.google.protobuf.Any;
import com.google.protobuf.Empty;
@@ -45,6 +46,7 @@
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
@@ -63,7 +65,6 @@
public class DatabaseAdminGaxTest {
public static class DelayedStatusRuntimeException extends RuntimeException {
private final long millis;
private boolean hasWaited = false;

public DelayedStatusRuntimeException(StatusRuntimeException cause, long millis) {
super(cause);
@@ -72,14 +73,7 @@ public DelayedStatusRuntimeException(StatusRuntimeException cause, long millis)

@Override
public synchronized Throwable getCause() {
if (!hasWaited) {
try {
Thread.sleep(millis);
hasWaited = true;
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
Uninterruptibles.sleepUninterruptibly(millis, TimeUnit.MILLISECONDS);
return super.getCause();
}
}
@@ -29,6 +29,7 @@
import com.google.cloud.spanner.admin.instance.v1.MockInstanceAdminImpl;
import com.google.common.base.Throwables;
import com.google.common.collect.Lists;
import com.google.common.util.concurrent.Uninterruptibles;
import com.google.protobuf.AbstractMessage;
import com.google.protobuf.Any;
import com.google.protobuf.Empty;
@@ -52,6 +53,7 @@
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
@@ -70,7 +72,6 @@
public class InstanceAdminGaxTest {
public static class DelayedStatusRuntimeException extends RuntimeException {
private final long millis;
private boolean hasWaited = false;

public DelayedStatusRuntimeException(StatusRuntimeException cause, long millis) {
super(cause);
@@ -79,14 +80,7 @@ public DelayedStatusRuntimeException(StatusRuntimeException cause, long millis)

@Override
public synchronized Throwable getCause() {
if (!hasWaited) {
try {
Thread.sleep(millis);
hasWaited = true;
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
Uninterruptibles.sleepUninterruptibly(millis, TimeUnit.MILLISECONDS);
return super.getCause();
}
}
@@ -588,14 +588,14 @@ private boolean matchesFilter(Object obj, String filter) throws Exception {
Operation operation = (Operation) obj;
Pattern pattern =
Pattern.compile(
"(?:\\(metadata.(?:name|database):(.*)\\)|\\(name:(.*)/operations/\\)) AND \\(metadata.@type:type.googleapis.com/(.*)\\)");
"(?:\\(metadata.@type:type.googleapis.com/(.*)\\)) AND (?:\\(metadata.(?:name|database):(.*)\\)|\\(name:(.*)/operations/\\))");
Matcher matcher = pattern.matcher(filter);
if (matcher.matches()) {
String objectName = matcher.group(1);
String type = matcher.group(1);
String objectName = matcher.group(2);
if (objectName == null) {
objectName = matcher.group(2);
objectName = matcher.group(3);
}
String type = matcher.group(3);
Any anyMetadata = operation.getMetadata();
if (anyMetadata.getTypeUrl().endsWith(type)) {
if (type.equals(CreateBackupMetadata.getDescriptor().getFullName())) {

0 comments on commit d80428a

Please sign in to comment.