maedhroz commented on a change in pull request #1329:
URL: https://github.com/apache/cassandra/pull/1329#discussion_r752406097



##########
File path: 
test/distributed/org/apache/cassandra/distributed/test/FailureLoggingTest.java
##########
@@ -0,0 +1,175 @@
+/*
+ * 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;
+
+import java.io.IOException;
+import java.util.List;
+
+import net.bytebuddy.ByteBuddy;
+import net.bytebuddy.dynamic.loading.ClassLoadingStrategy;
+import net.bytebuddy.implementation.MethodDelegation;
+
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import org.apache.cassandra.db.SinglePartitionReadCommand;
+import org.apache.cassandra.db.partitions.PartitionIterator;
+import org.apache.cassandra.distributed.Cluster;
+import org.apache.cassandra.distributed.api.ConsistencyLevel;
+import org.apache.cassandra.distributed.api.LogResult;
+import org.apache.cassandra.exceptions.UnavailableException;
+import org.apache.cassandra.service.StorageProxy;
+import org.apache.cassandra.service.StorageService;
+import org.apache.cassandra.service.reads.range.RangeCommandIterator;
+
+import static net.bytebuddy.matcher.ElementMatchers.named;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+public class FailureLoggingTest extends TestBaseImpl
+{
+    private static Cluster cluster;
+    
+    @BeforeClass
+    public static void setUpCluster() throws IOException
+    {
+        System.setProperty("cassandra.request_failure_log_interval_seconds", 
"0");
+        cluster = 
init(Cluster.build(1).withInstanceInitializer(BBRequestFailures::install).start());
+        cluster.schemaChange("create table "+KEYSPACE+".tbl (id int primary 
key, i int)");
+    }
+
+    @AfterClass
+    public static void tearDownCluster()
+    {
+        cluster.close();
+    }
+    
+    @Before
+    public void resetBootstrappingState()
+    {
+        cluster.get(1).callOnInstance(() -> BBRequestFailures.bootstrapping = 
false);
+        
+    }
+    
+    @Test
+    public void testRequestBootstrapFail() throws Throwable
+    {
+        cluster.get(1).callOnInstance(() -> BBRequestFailures.bootstrapping = 
true);
+        long mark = cluster.get(1).logs().mark();
+
+        try
+        {
+            cluster.coordinator(1).execute("select * from " + KEYSPACE + ".tbl 
where id = 55", ConsistencyLevel.ALL);
+            fail("Query should fail");
+        }
+        catch (RuntimeException e)
+        {
+            LogResult<List<String>> result = cluster.get(1).logs().grep(mark, 
"while executing SELECT");
+            assertEquals(1, result.getResult().size());
+            assertTrue(result.getResult().get(0).contains("Cannot read from a 
bootstrapping node"));
+        }
+    }
+
+    @Test
+    public void testRangeRequestFail() throws Throwable
+    {
+        long mark = cluster.get(1).logs().mark();
+
+        try
+        {
+            cluster.coordinator(1).execute("select * from " + KEYSPACE + 
".tbl", ConsistencyLevel.ALL);
+            fail("Query should fail");
+        }
+        catch (RuntimeException e)
+        {
+            LogResult<List<String>> result = cluster.get(1).logs().grep(mark, 
"while executing SELECT");
+            assertEquals(1, result.getResult().size());
+            assertTrue(result.getResult().get(0).contains("Cannot achieve 
consistency level"));
+        }
+    }
+
+    @Test
+    public void testReadRequestFail() throws Throwable
+    {
+        long mark = cluster.get(1).logs().mark();
+
+        try
+        {
+            cluster.coordinator(1).execute("select * from " + KEYSPACE + ".tbl 
where id = 55", ConsistencyLevel.ALL);
+            fail("Query should fail");
+        }
+        catch (RuntimeException e)
+        {
+            LogResult<List<String>> result = cluster.get(1).logs().grep(mark, 
"while executing SELECT");
+            assertEquals(1, result.getResult().size());
+            assertTrue(result.getResult().get(0).contains("Cannot achieve 
consistency level"));
+        }
+    }

Review comment:
       The tests all call `mark()` before the query is executed and use the 
returned value afterward when grep'ing the logs, right?




-- 
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]

Reply via email to