-
Notifications
You must be signed in to change notification settings - Fork 271
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a step in BsaDownloadAction to apply the diffs from the most recent download. This includes: - Add new labels and remove deleted labels to the `BsaLabel` table. - Add new entries to the `BsaDomainInUse` table if applicable. These are registered/reserved domains that match the new labels. - Generate list of domains that are not blocked and save them in a GCS file. These include all domains from the previous step as well as domains derived from invalid labels. More tests are needed but this PR successfully processed a real download.
- Loading branch information
Showing
30 changed files
with
1,250 additions
and
94 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
common/src/main/java/google/registry/util/BatchedStreams.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright 2023 The Nomulus Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package google.registry.util; | ||
|
||
import static com.google.common.base.Preconditions.checkArgument; | ||
import static com.google.common.collect.Iterators.partition; | ||
import static com.google.common.collect.Iterators.transform; | ||
import static com.google.common.collect.Streams.stream; | ||
import static java.lang.Math.min; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import java.util.stream.Stream; | ||
|
||
/** Utilities for breaking up a {@link Stream} into batches. */ | ||
public final class BatchedStreams { | ||
|
||
static final int MAX_BATCH = 1024 * 1024; | ||
|
||
private BatchedStreams() {} | ||
|
||
/** | ||
* Transform a flat {@link Stream} into a {@code Stream} of batches. | ||
* | ||
* <p>Closing the returned stream does not close the original stream. | ||
*/ | ||
public static <T> Stream<ImmutableList<T>> batch(Stream<T> stream, int batchSize) { | ||
checkArgument(batchSize > 0, "batchSize must be a positive integer."); | ||
return stream( | ||
transform(partition(stream.iterator(), min(MAX_BATCH, batchSize)), ImmutableList::copyOf)); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
common/src/test/java/google/registry/util/BatchedStreamsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright 2023 The Nomulus Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package google.registry.util; | ||
|
||
import static com.google.common.truth.Truth.assertThat; | ||
import static google.registry.util.BatchedStreams.batch; | ||
import static java.util.stream.Collectors.counting; | ||
import static java.util.stream.Collectors.groupingBy; | ||
import static org.junit.Assert.assertThrows; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import java.util.stream.IntStream; | ||
import java.util.stream.Stream; | ||
import org.junit.jupiter.api.Test; | ||
|
||
/** Unit tests for {@link BatchedStreams}. */ | ||
public class BatchedStreamsTest { | ||
|
||
@Test | ||
void invalidBatchSize() { | ||
assertThat(assertThrows(IllegalArgumentException.class, () -> batch(Stream.of(), 0))) | ||
.hasMessageThat() | ||
.contains("must be a positive integer"); | ||
} | ||
|
||
@Test | ||
void batch_success() { | ||
Stream<Integer> data = IntStream.rangeClosed(0, 1_000_000).boxed(); | ||
assertThat(batch(data, 1000).map(ImmutableList::size).collect(groupingBy(x -> x, counting()))) | ||
.containsExactly(1000, 1000L, 1, 1L); | ||
} | ||
|
||
@Test | ||
void batch_partialBatch() { | ||
Stream<Integer> data = Stream.of(1, 2, 3); | ||
assertThat(batch(data, 1000).map(ImmutableList::size).collect(groupingBy(x -> x, counting()))) | ||
.containsExactly(3, 1L); | ||
} | ||
|
||
@Test | ||
void batch_truncateBatchSize() { | ||
Stream<Integer> data = IntStream.range(0, 1024 * 2048).boxed(); | ||
assertThat( | ||
batch(data, 2_000_000).map(ImmutableList::size).collect(groupingBy(x -> x, counting()))) | ||
.containsExactly(1024 * 1024, 2L); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.