maedhroz commented on a change in pull request #1301: URL: https://github.com/apache/cassandra/pull/1301#discussion_r797093813
########## File path: test/distributed/org/apache/cassandra/distributed/test/streaming/StreamCloseInMiddleTest.java ########## @@ -0,0 +1,204 @@ +/* + * 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.distributed.test.streaming; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.Callable; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Collectors; + +import org.junit.Test; + +import net.bytebuddy.ByteBuddy; +import net.bytebuddy.dynamic.loading.ClassLoadingStrategy; +import net.bytebuddy.implementation.MethodDelegation; +import net.bytebuddy.implementation.bind.annotation.SuperCall; +import org.apache.cassandra.db.rows.UnfilteredRowIterator; +import org.apache.cassandra.db.streaming.CassandraIncomingFile; +import org.apache.cassandra.distributed.Cluster; +import org.apache.cassandra.distributed.api.Feature; +import org.apache.cassandra.distributed.api.IInvokableInstance; +import org.apache.cassandra.distributed.api.LogResult; +import org.apache.cassandra.distributed.api.TokenSupplier; +import org.apache.cassandra.distributed.shared.ClusterUtils; +import org.apache.cassandra.distributed.test.TestBaseImpl; +import org.apache.cassandra.io.sstable.format.RangeAwareSSTableWriter; +import org.apache.cassandra.io.sstable.format.big.BigTableZeroCopyWriter; +import org.apache.cassandra.io.util.SequentialWriter; +import org.assertj.core.api.Assertions; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static net.bytebuddy.matcher.ElementMatchers.takesArguments; + +public class StreamCloseInMiddleTest extends TestBaseImpl +{ + @Test + public void zeroCopy() throws IOException + { + streamClose(true); + } + + @Test + public void notZeroCopy() throws IOException + { + streamClose(false); + } + + private void streamClose(boolean zeroCopyStreaming) throws IOException + { + try (Cluster cluster = Cluster.build(2) + .withTokenSupplier(TokenSupplier.evenlyDistributedTokens(3)) + .withInstanceInitializer(BBHelper::install) + .withConfig(c -> c.with(Feature.values()) + .set("stream_entire_sstables", zeroCopyStreaming) + // when die, this will try to halt JVM, which is easier to validate in the test + // other levels require checking state of the subsystems + .set("disk_failure_policy", "die")) + .start()) + { + init(cluster); + + cluster.schemaChange(withKeyspace("CREATE TABLE %s.tbl (pk int PRIMARY KEY)")); + + triggerStreaming(cluster, zeroCopyStreaming); + // make sure disk failure policy is not triggered + assertNoNodeShutdown(cluster); + + // now bootstrap a new node; streaming will fail + IInvokableInstance node3 = ClusterUtils.addInstance(cluster, c -> c.set("auto_bootstrap", true)); + node3.startup(); + for (String line : Arrays.asList("Error while waiting on bootstrap to complete. Bootstrap will have to be restarted", // bootstrap failed + "Some data streaming failed. Use nodetool to check bootstrap state and resume")) // didn't join ring because bootstrap failed + Assertions.assertThat(node3.logs().grep(line).getResult()) + .hasSize(1); Review comment: nit: Could we just look at node 3's bootstrap state? Something like making sure this isn't `COMPLETED`: ``` String state = node3.callsOnInstance(() -> SystemKeyspace.getBootstrapState().toString()).call(); ``` ...or is the worry that without explicitly looking at the logs, and without a specific `FAILED` state, being `IN_PROGRESS` isn't a foolproof assertion? (I guess we could also do something like revert to `NEEDS_BOOTSTRAP` instead of creating a new state.) -- 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]

