-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat(storage): Parameterized test setup for RCU Integration Testing #14119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
f4cbede
5dc69d5
ee8a737
61f4ee8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -20,10 +20,14 @@ | |||||
|
|
||||||
| import com.google.cloud.storage.TransportCompatibility.Transport; | ||||||
| import com.google.cloud.storage.it.runner.annotations.Backend; | ||||||
| import com.google.cloud.storage.it.runner.annotations.Colocation; | ||||||
| import com.google.cloud.storage.it.runner.annotations.CrossRun; | ||||||
| import com.google.cloud.storage.it.runner.annotations.LocationType; | ||||||
| import com.google.common.base.MoreObjects; | ||||||
| import com.google.common.collect.ImmutableSet; | ||||||
| import java.util.Collections; | ||||||
| import java.util.Locale; | ||||||
| import java.util.Set; | ||||||
| import java.util.Objects; | ||||||
| import javax.annotation.concurrent.Immutable; | ||||||
| import javax.annotation.concurrent.ThreadSafe; | ||||||
|
|
@@ -39,10 +43,18 @@ public final class CrossRunIntersection { | |||||
|
|
||||||
| private final @Nullable Backend backend; | ||||||
| private final @Nullable Transport transport; | ||||||
| private final @Nullable LocationType locationType; | ||||||
| private final @Nullable Colocation colocation; | ||||||
|
|
||||||
| private CrossRunIntersection(@Nullable Backend backend, @Nullable Transport transport) { | ||||||
| private CrossRunIntersection( | ||||||
| @Nullable Backend backend, | ||||||
| @Nullable Transport transport, | ||||||
| @Nullable LocationType locationType, | ||||||
| @Nullable Colocation colocation) { | ||||||
| this.backend = backend; | ||||||
| this.transport = transport; | ||||||
| this.locationType = locationType; | ||||||
| this.colocation = colocation; | ||||||
| } | ||||||
|
|
||||||
| @Nullable | ||||||
|
|
@@ -55,19 +67,45 @@ public Transport getTransport() { | |||||
| return transport; | ||||||
| } | ||||||
|
|
||||||
| @Nullable | ||||||
| public LocationType getLocationType() { | ||||||
| return locationType; | ||||||
| } | ||||||
|
|
||||||
| @Nullable | ||||||
| public Colocation getColocation() { | ||||||
| return colocation; | ||||||
| } | ||||||
|
|
||||||
| public CrossRunIntersection clearBackend() { | ||||||
| if (backend == null) { | ||||||
| return this; | ||||||
| } else { | ||||||
| return new CrossRunIntersection(null, transport); | ||||||
| return new CrossRunIntersection(null, transport, locationType, colocation); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| public CrossRunIntersection clearTransport() { | ||||||
| if (transport == null) { | ||||||
| return this; | ||||||
| } else { | ||||||
| return new CrossRunIntersection(backend, null); | ||||||
| return new CrossRunIntersection(backend, null, locationType, colocation); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| public CrossRunIntersection clearLocationType() { | ||||||
| if (locationType == null) { | ||||||
| return this; | ||||||
| } else { | ||||||
| return new CrossRunIntersection(backend, transport, null, colocation); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| public CrossRunIntersection clearColocation() { | ||||||
| if (colocation == null) { | ||||||
| return this; | ||||||
| } else { | ||||||
| return new CrossRunIntersection(backend, transport, locationType, null); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -76,7 +114,7 @@ public CrossRunIntersection withBackend(Backend backend) { | |||||
| if (this.backend == backend) { | ||||||
| return this; | ||||||
| } else { | ||||||
| return new CrossRunIntersection(backend, transport); | ||||||
| return new CrossRunIntersection(backend, transport, locationType, colocation); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -85,7 +123,25 @@ public CrossRunIntersection withTransport(Transport transport) { | |||||
| if (this.transport == transport) { | ||||||
| return this; | ||||||
| } else { | ||||||
| return new CrossRunIntersection(backend, transport); | ||||||
| return new CrossRunIntersection(backend, transport, locationType, colocation); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| public CrossRunIntersection withLocationType(LocationType locationType) { | ||||||
| requireNonNull(locationType, "locationType must be non null"); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The method
Suggested change
|
||||||
| if (this.locationType == locationType) { | ||||||
| return this; | ||||||
| } else { | ||||||
| return new CrossRunIntersection(backend, transport, locationType, colocation); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| public CrossRunIntersection withColocation(Colocation colocation) { | ||||||
| requireNonNull(colocation, "colocation must be non null"); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The method
Suggested change
|
||||||
| if (this.colocation == colocation) { | ||||||
| return this; | ||||||
| } else { | ||||||
| return new CrossRunIntersection(backend, transport, locationType, colocation); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -107,6 +163,20 @@ public boolean anyMatch(CrossRunIntersection other) { | |||||
| l = l.clearTransport(); | ||||||
| } | ||||||
|
|
||||||
| if (l.locationType == null) { | ||||||
| r = r.clearLocationType(); | ||||||
| } | ||||||
| if (r.locationType == null) { | ||||||
| l = l.clearLocationType(); | ||||||
| } | ||||||
|
|
||||||
| if (l.colocation == null) { | ||||||
| r = r.clearColocation(); | ||||||
| } | ||||||
| if (r.colocation == null) { | ||||||
| l = l.clearColocation(); | ||||||
| } | ||||||
|
|
||||||
| return l.equals(r); | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -119,7 +189,9 @@ public boolean anyMatch(CrossRunIntersection other) { | |||||
| public String fmtSuiteName() { | ||||||
| String t = transport != null ? transport.toString() : "NULL_TRANSPORT"; | ||||||
| String b = backend != null ? backend.toString() : "NULL_BACKEND"; | ||||||
| return String.format(Locale.US, "[%s][%s]", t, b); | ||||||
| String lt = locationType != null ? locationType.toString() : "NULL_LOCATION"; | ||||||
| String c = colocation != null ? colocation.toString() : "NULL_COLOCATION"; | ||||||
| return String.format(Locale.US, "[%s][%s][%s][%s]", t, b, lt, c); | ||||||
| } | ||||||
|
|
||||||
| @Override | ||||||
|
|
@@ -131,54 +203,90 @@ public boolean equals(Object o) { | |||||
| return false; | ||||||
| } | ||||||
| CrossRunIntersection crossRunIntersection = (CrossRunIntersection) o; | ||||||
| return backend == crossRunIntersection.backend && transport == crossRunIntersection.transport; | ||||||
| return backend == crossRunIntersection.backend | ||||||
| && transport == crossRunIntersection.transport | ||||||
| && locationType == crossRunIntersection.locationType | ||||||
| && colocation == crossRunIntersection.colocation; | ||||||
| } | ||||||
|
|
||||||
| @Override | ||||||
| public int hashCode() { | ||||||
| return Objects.hash(backend, transport); | ||||||
| return Objects.hash(backend, transport, locationType, colocation); | ||||||
| } | ||||||
|
|
||||||
| @Override | ||||||
| public String toString() { | ||||||
| return MoreObjects.toStringHelper(this) | ||||||
| .add("backend", backend) | ||||||
| .add("transport", transport) | ||||||
| .add("locationType", locationType) | ||||||
| .add("colocation", colocation) | ||||||
| .toString(); | ||||||
| } | ||||||
|
|
||||||
| public static CrossRunIntersection of(@Nullable Backend t, @Nullable Transport s) { | ||||||
| return new CrossRunIntersection(t, s); | ||||||
| public static CrossRunIntersection of(@Nullable Backend b, @Nullable Transport t) { | ||||||
| return new CrossRunIntersection(b, t, null, null); | ||||||
| } | ||||||
|
|
||||||
| public static CrossRunIntersection of( | ||||||
| @Nullable Backend b, | ||||||
| @Nullable Transport t, | ||||||
| @Nullable LocationType lt, | ||||||
| @Nullable Colocation c) { | ||||||
| return new CrossRunIntersection(b, t, lt, c); | ||||||
| } | ||||||
|
|
||||||
| public static ImmutableSet<CrossRunIntersection> expand(CrossRun.Ignore i) { | ||||||
| ImmutableSet<Backend> backends = ImmutableSet.copyOf(i.backends()); | ||||||
| ImmutableSet<Transport> transports = ImmutableSet.copyOf(i.transports()); | ||||||
| return expand(backends, transports); | ||||||
| ImmutableSet<LocationType> locations = ImmutableSet.copyOf(i.locations()); | ||||||
| ImmutableSet<Colocation> colocations = ImmutableSet.copyOf(i.colocations()); | ||||||
| return expand(backends, transports, locations, colocations); | ||||||
| } | ||||||
|
|
||||||
| public static ImmutableSet<CrossRunIntersection> expand(CrossRun.Exclude i) { | ||||||
| ImmutableSet<Backend> backends = ImmutableSet.copyOf(i.backends()); | ||||||
| ImmutableSet<Transport> transports = ImmutableSet.copyOf(i.transports()); | ||||||
| return expand(backends, transports); | ||||||
| ImmutableSet<LocationType> locations = ImmutableSet.copyOf(i.locations()); | ||||||
| ImmutableSet<Colocation> colocations = ImmutableSet.copyOf(i.colocations()); | ||||||
| return expand(backends, transports, locations, colocations); | ||||||
| } | ||||||
|
|
||||||
| public static ImmutableSet<CrossRunIntersection> expand( | ||||||
| ImmutableSet<Backend> backends, ImmutableSet<@Nullable Transport> transports) { | ||||||
| if (backends.isEmpty() && transports.isEmpty()) { | ||||||
| ImmutableSet<Backend> backends, | ||||||
| ImmutableSet<@Nullable Transport> transports, | ||||||
| ImmutableSet<@Nullable LocationType> locations, | ||||||
| ImmutableSet<@Nullable Colocation> colocations) { | ||||||
| if (backends.isEmpty() && transports.isEmpty() && locations.isEmpty() && colocations.isEmpty()) { | ||||||
| return ImmutableSet.of(); | ||||||
| } else if (!backends.isEmpty() && !transports.isEmpty()) { | ||||||
| return backends.stream() | ||||||
| .flatMap(t -> transports.stream().map(s -> new CrossRunIntersection(t, s))) | ||||||
| .collect(ImmutableSet.toImmutableSet()); | ||||||
| } else if (!backends.isEmpty()) { | ||||||
| return backends.stream() | ||||||
| .map(t -> new CrossRunIntersection(t, null)) | ||||||
| .collect(ImmutableSet.toImmutableSet()); | ||||||
| } else { | ||||||
| return transports.stream() | ||||||
| .map(s -> new CrossRunIntersection(null, s)) | ||||||
| .collect(ImmutableSet.toImmutableSet()); | ||||||
| } | ||||||
|
|
||||||
| Set<@Nullable Backend> bSet = | ||||||
| backends.isEmpty() ? Collections.singleton((Backend) null) : backends; | ||||||
| Set<@Nullable Transport> tSet = | ||||||
| transports.isEmpty() ? Collections.singleton((Transport) null) : transports; | ||||||
| Set<@Nullable LocationType> lSet = | ||||||
| locations.isEmpty() ? Collections.singleton((LocationType) null) : locations; | ||||||
| Set<@Nullable Colocation> cSet = | ||||||
| colocations.isEmpty() ? Collections.singleton((Colocation) null) : colocations; | ||||||
|
|
||||||
| return bSet.stream() | ||||||
| .flatMap( | ||||||
| b -> | ||||||
| tSet.stream() | ||||||
| .flatMap( | ||||||
| t -> | ||||||
| lSet.stream() | ||||||
| .flatMap( | ||||||
| l -> | ||||||
| cSet.stream() | ||||||
| .map(c -> new CrossRunIntersection(b, t, l, c))))) | ||||||
| .filter( | ||||||
| i -> | ||||||
| !(i.backend == null | ||||||
| && i.transport == null | ||||||
| && i.locationType == null | ||||||
| && i.colocation == null)) | ||||||
| .collect(ImmutableSet.toImmutableSet()); | ||||||
| } | ||||||
| } | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
host.indexOf(path)to find the start of the path is generally safe here, but usinghost.length() - path.length()is more robust, direct, and avoids searching the string, as the path is guaranteed to be at the end of the host URL.