frankgh commented on code in PR #171:
URL: https://github.com/apache/cassandra-sidecar/pull/171#discussion_r1956725029
##########
server/src/main/java/org/apache/cassandra/sidecar/tasks/PeriodicTaskExecutor.java:
##########
Review Comment:
I think having this at debug level is useful. Can we revert these changes?
##########
server/src/test/java/org/apache/cassandra/sidecar/db/RestoreSliceTest.java:
##########
@@ -83,52 +80,46 @@ void testCreateFromRow()
assertThat(sliceFromRow).isEqualTo(slice);
}
+ @Test
+ void testCreateFromPayload()
+ {
+ CreateSliceRequestPayload payload = new
CreateSliceRequestPayload("slice-id", 0, "bucket", "key", "checksum",
+
BigInteger.ONE, // first token
+
BigInteger.TEN, // end token
+
123L, // uncompressed size
+
100L); // compressed size
+ RestoreSlice slice =
RestoreSlice.builder().createSliceRequestPayload(payload).build();
+ assertThat(slice.sliceId()).isEqualTo("slice-id");
+ assertThat(slice.bucketId()).isEqualTo((short) 0);
+ assertThat(slice.bucket()).isEqualTo("bucket");
+ assertThat(slice.key()).isEqualTo("key");
+ assertThat(slice.checksum()).isEqualTo("checksum");
+ assertThat(slice.startToken())
+ .describedAs("Start token is exclusive end in the range")
+ .isEqualTo(BigInteger.ZERO);
+ assertThat(slice.endToken()).isEqualTo(BigInteger.TEN);
+ assertThat(slice.uncompressedSize()).isEqualTo(123L);
+ assertThat(slice.compressedSize()).isEqualTo(100L);
+ }
+
@Test
void testNoSplit()
{
RestoreSlice slice = createTestingSlice(UUIDs.timeBased(), "slice-id",
0L, 10L);
- List<RestoreSlice> result = slice.splitMaybe(null);
- assertThat(result).hasSize(1);
- assertThat(result.get(0)).isSameAs(slice);
-
- TokenRangeReplicasResponse topology =
mock(TokenRangeReplicasResponse.class);
-
when(topology.writeReplicas()).thenReturn(Collections.singletonList(new
ReplicaInfo("-10", "10", null)));
- // range in topology fully encloses the slice
- result = slice.splitMaybe(topology);
- assertThat(result).hasSize(1);
- assertThat(result.get(0)).isSameAs(slice);
+ RestoreSlice result = slice.trimMaybe(new TokenRange(-10L, 10L));
+ assertThat(result)
+ .describedAs("No trim is done when fully enclosed by the local token
range")
+ .isSameAs(slice);
}
@Test
void testSplitNoOverlap()
{
RestoreSlice slice = createTestingSlice(UUIDs.timeBased(), "slice-id",
0L, 10L);
- TokenRangeReplicasResponse topology =
mock(TokenRangeReplicasResponse.class);
-
when(topology.writeReplicas()).thenReturn(Collections.singletonList(new
ReplicaInfo("100", "110", null)));
// (0, 10] does not overlap with (100, 110]
- assertThatThrownBy(() -> slice.splitMaybe(topology))
+ assertThatThrownBy(() -> slice.trimMaybe(new TokenRange(100L, 110L)))
Review Comment:
maybe update the test name?
##########
server/src/test/integration/org/apache/cassandra/sidecar/restore/RestoreJobTestUtils.java:
##########
@@ -0,0 +1,180 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.cassandra.sidecar.restore;
+
+import java.math.BigInteger;
+import java.util.UUID;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Consumer;
+
+import com.datastax.driver.core.utils.UUIDs;
+import com.google.inject.AbstractModule;
+import com.google.inject.Module;
+import com.google.inject.Provides;
+import com.google.inject.Singleton;
+import io.netty.handler.codec.http.HttpResponseStatus;
+import io.vertx.core.Promise;
+import io.vertx.core.buffer.Buffer;
+import io.vertx.ext.web.client.HttpResponse;
+import io.vertx.ext.web.client.WebClient;
+import org.apache.cassandra.sidecar.cluster.locator.LocalTokenRangesProvider;
+import org.apache.cassandra.sidecar.common.data.ConsistencyLevel;
+import
org.apache.cassandra.sidecar.common.request.data.CreateRestoreJobRequestPayload;
+import
org.apache.cassandra.sidecar.common.request.data.CreateSliceRequestPayload;
+import
org.apache.cassandra.sidecar.common.request.data.UpdateRestoreJobRequestPayload;
+import org.apache.cassandra.sidecar.common.server.data.QualifiedTableName;
+import org.apache.cassandra.sidecar.concurrent.ExecutorPools;
+import org.apache.cassandra.sidecar.config.SidecarConfiguration;
+import org.apache.cassandra.sidecar.db.RestoreRange;
+import org.apache.cassandra.sidecar.db.RestoreRangeDatabaseAccessor;
+import org.apache.cassandra.sidecar.db.schema.SidecarSchema;
+import org.apache.cassandra.sidecar.foundation.RestoreJobSecretsGen;
+import org.apache.cassandra.sidecar.metrics.SidecarMetrics;
+import org.apache.cassandra.sidecar.tasks.ScheduleDecision;
+import org.apache.cassandra.sidecar.utils.SSTableImporter;
+
+import static org.apache.cassandra.testing.utils.AssertionUtils.getBlocking;
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Test utils for restore job related testing
+ */
+public class RestoreJobTestUtils
+{
+ private RestoreJobTestUtils()
+ {
+ throw new UnsupportedOperationException("Do not instantiate me");
+ }
+
+ public static RestoreJobClient client(WebClient client, String host, int
port)
+ {
+ return new RestoreJobClient(client, host, port);
+ }
+
+ public static void assertRestoreRange(RestoreRange range, long startToken,
long endToken)
+ {
+ assertRestoreRange(range, startToken, endToken, null);
+ }
+
+ public static void assertRestoreRange(RestoreRange range, long startToken,
long endToken, Consumer<RestoreRange> additionalAssertions)
+ {
+ assertThat(range.startToken())
+ .describedAs("startTokens do not match")
+ .isEqualTo(BigInteger.valueOf(startToken));
+ assertThat(range.endToken())
+ .describedAs("endTokens do not match")
+ .isEqualTo(BigInteger.valueOf(endToken));
+ if (additionalAssertions != null)
+ {
+ additionalAssertions.accept(range);
+ }
+ }
+
+ public static UUID createJob(RestoreJobTestUtils.RestoreJobClient
testClient, QualifiedTableName tableName)
+ {
+ UUID jobId = UUIDs.timeBased();
+ long expireAt = System.currentTimeMillis() +
TimeUnit.MINUTES.toMillis(2);
+ CreateRestoreJobRequestPayload payload = CreateRestoreJobRequestPayload
+
.builder(RestoreJobSecretsGen.genRestoreJobSecrets(), expireAt)
+ .jobId(jobId)
+
.consistencyLevel(ConsistencyLevel.LOCAL_QUORUM, "datacenter1").build();
+ testClient.createRestoreJob(tableName, payload);
+ return jobId;
+ }
+
+ public static Module disableRestoreProcessor()
+ {
+ return new AbstractModule()
+ {
+ @Provides
+ @Singleton
+ public RestoreProcessor processor(ExecutorPools executorPools,
+ SidecarConfiguration config,
+ SidecarSchema sidecarSchema,
+ StorageClientPool s3ClientPool,
+ SSTableImporter importer,
+ RestoreRangeDatabaseAccessor
rangeDatabaseAccessor,
+ RestoreJobUtil restoreJobUtil,
+ LocalTokenRangesProvider
localTokenRangesProvider,
+ SidecarMetrics metrics)
+ {
+ return new RestoreProcessor(executorPools, config,
sidecarSchema,
+ s3ClientPool, importer,
rangeDatabaseAccessor,
+ restoreJobUtil,
localTokenRangesProvider, metrics)
+ {
+ @Override
+ public void execute(Promise<Void> promise)
+ {
+ // disable task processing
+ }
Review Comment:
probably sufficient to have the `SKIP` schedule decision
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]