You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by sa...@apache.org on 2015/05/19 13:11:01 UTC
[7/9] cassandra git commit: Add test for triggers which throw IRE
Add test for triggers which throw IRE
Patch by Sam Tunnicliffe; reviewed by brandonwilliams for CASSANDRA-9334
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/86c9c00e
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/86c9c00e
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/86c9c00e
Branch: refs/heads/cassandra-2.2
Commit: 86c9c00e98a1867deff3b8acc883d224b532197b
Parents: e2723a4
Author: Sam Tunnicliffe <sa...@beobal.com>
Authored: Tue May 12 16:26:24 2015 +0100
Committer: Sam Tunnicliffe <sa...@beobal.com>
Committed: Tue May 19 12:02:40 2015 +0100
----------------------------------------------------------------------
.../apache/cassandra/triggers/TriggersTest.java | 49 +++++++++++++++-----
1 file changed, 38 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/86c9c00e/test/unit/org/apache/cassandra/triggers/TriggersTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/triggers/TriggersTest.java b/test/unit/org/apache/cassandra/triggers/TriggersTest.java
index 41d4bb8..b0a5aca 100644
--- a/test/unit/org/apache/cassandra/triggers/TriggersTest.java
+++ b/test/unit/org/apache/cassandra/triggers/TriggersTest.java
@@ -22,18 +22,13 @@ import java.nio.ByteBuffer;
import java.util.Collection;
import java.util.Collections;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.*;
import org.apache.cassandra.SchemaLoader;
import org.apache.cassandra.config.Schema;
import org.apache.cassandra.cql3.QueryProcessor;
import org.apache.cassandra.cql3.UntypedResultSet;
-import org.apache.cassandra.db.ArrayBackedSortedColumns;
-import org.apache.cassandra.db.BufferCell;
-import org.apache.cassandra.db.ColumnFamily;
+import org.apache.cassandra.db.*;
import org.apache.cassandra.db.ConsistencyLevel;
import org.apache.cassandra.db.Mutation;
import org.apache.cassandra.exceptions.ConfigurationException;
@@ -42,11 +37,10 @@ import org.apache.cassandra.service.StorageService;
import org.apache.cassandra.thrift.*;
import org.apache.thrift.protocol.TBinaryProtocol;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
import static org.apache.cassandra.utils.ByteBufferUtil.bytes;
import static org.apache.cassandra.utils.ByteBufferUtil.toInt;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
public class TriggersTest
{
@@ -61,12 +55,12 @@ public class TriggersTest
public static void beforeTest() throws ConfigurationException
{
SchemaLoader.loadSchema();
+ StorageService.instance.initServer(0);
}
@Before
public void setup() throws Exception
{
- StorageService.instance.initServer(0);
if (thriftServer == null || ! thriftServer.isRunning())
{
thriftServer = new ThriftServer(InetAddress.getLocalHost(), 9170, 50);
@@ -283,6 +277,29 @@ public class TriggersTest
}
}
+ @Test(expected=RuntimeException.class)
+ public void ifTriggerThrowsErrorNoMutationsAreApplied() throws Exception
+ {
+ String cf = "cf" + System.nanoTime();
+ try
+ {
+ setupTableWithTrigger(cf, ErrorTrigger.class);
+ String cql = String.format("INSERT INTO %s.%s (k, v1) VALUES (11, 11)", ksName, cf);
+ QueryProcessor.process(cql, ConsistencyLevel.ONE);
+ }
+ catch (Exception e)
+ {
+ Throwable cause = e.getCause();
+ assertTrue((cause instanceof org.apache.cassandra.exceptions.InvalidRequestException));
+ assertTrue(cause.getMessage().equals(ErrorTrigger.MESSAGE));
+ throw e;
+ }
+ finally
+ {
+ assertUpdateNotExecuted(cf, 11);
+ }
+ }
+
private void setupTableWithTrigger(String cf, Class<? extends ITrigger> triggerImpl)
throws RequestExecutionException
{
@@ -350,4 +367,14 @@ public class TriggersTest
return Collections.singletonList(new Mutation(ksName, key, extraUpdate));
}
}
+
+ public static class ErrorTrigger implements ITrigger
+ {
+ public static final String MESSAGE = "Thrown by ErrorTrigger";
+ public Collection<Mutation> augment(ByteBuffer partitionKey, ColumnFamily update)
+ {
+ throw new org.apache.cassandra.exceptions.InvalidRequestException(MESSAGE);
+ }
+ }
+
}