Repository: cassandra Updated Branches: refs/heads/trunk 1ad9d5567 -> 6f067af51
Do not wrap CassandraException in TriggerExecutor Patch by Branimir Lambov; reviewed by Sam Tunnicliffe for CASSANDRA-9421 Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/6f067af5 Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/6f067af5 Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/6f067af5 Branch: refs/heads/trunk Commit: 6f067af5157be9ed8df566d0a5df042c694215e2 Parents: 1ad9d55 Author: Branimir Lambov <[email protected]> Authored: Fri Mar 18 11:50:35 2016 +0000 Committer: Sam Tunnicliffe <[email protected]> Committed: Fri Mar 18 11:57:43 2016 +0000 ---------------------------------------------------------------------- CHANGES.txt | 1 + .../cassandra/triggers/TriggerExecutor.java | 7 +++- .../apache/cassandra/triggers/TriggersTest.java | 40 ++++++++++++++++---- 3 files changed, 39 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/6f067af5/CHANGES.txt ---------------------------------------------------------------------- diff --git a/CHANGES.txt b/CHANGES.txt index c23c301..173d14f 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,5 @@ 3.6 + * Do not wrap CassandraException in TriggerExecutor (CASSANDRA-9421) * COPY TO should have higher double precision (CASSANDRA-11255) * Stress should exit with non-zero status after failure (CASSANDRA-10340) * Add client to cqlsh SHOW_SESSION (CASSANDRA-8958) http://git-wip-us.apache.org/repos/asf/cassandra/blob/6f067af5/src/java/org/apache/cassandra/triggers/TriggerExecutor.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/triggers/TriggerExecutor.java b/src/java/org/apache/cassandra/triggers/TriggerExecutor.java index 40d4094..8cfa3e2 100644 --- a/src/java/org/apache/cassandra/triggers/TriggerExecutor.java +++ b/src/java/org/apache/cassandra/triggers/TriggerExecutor.java @@ -31,6 +31,7 @@ import com.google.common.collect.Maps; import org.apache.cassandra.cql3.QueryProcessor; import org.apache.cassandra.db.*; import org.apache.cassandra.db.partitions.PartitionUpdate; +import org.apache.cassandra.exceptions.CassandraException; import org.apache.cassandra.exceptions.InvalidRequestException; import org.apache.cassandra.schema.TriggerMetadata; import org.apache.cassandra.schema.Triggers; @@ -231,9 +232,13 @@ public class TriggerExecutor } return tmutations; } + catch (CassandraException ex) + { + throw ex; + } catch (Exception ex) { - throw new RuntimeException(String.format("Exception while creating trigger on table with ID: %s", update.metadata().cfId), ex); + throw new RuntimeException(String.format("Exception while executing trigger on table with ID: %s", update.metadata().cfId), ex); } finally { http://git-wip-us.apache.org/repos/asf/cassandra/blob/6f067af5/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 13ecbe9..e5a2dd6 100644 --- a/test/unit/org/apache/cassandra/triggers/TriggersTest.java +++ b/test/unit/org/apache/cassandra/triggers/TriggersTest.java @@ -18,7 +18,6 @@ package org.apache.cassandra.triggers; import java.net.InetAddress; -import java.nio.ByteBuffer; import java.util.Collection; import java.util.Collections; @@ -35,7 +34,6 @@ import org.apache.cassandra.db.*; import org.apache.cassandra.db.ConsistencyLevel; import org.apache.cassandra.db.Mutation; import org.apache.cassandra.db.partitions.Partition; -import org.apache.cassandra.db.partitions.PartitionUpdate; import org.apache.cassandra.exceptions.ConfigurationException; import org.apache.cassandra.exceptions.RequestExecutionException; import org.apache.cassandra.service.StorageService; @@ -197,9 +195,7 @@ public class TriggersTest assertUpdateIsAugmented(6); } - // Unfortunately, an IRE thrown from StorageProxy.cas - // results in a RuntimeException from QueryProcessor.process - @Test(expected=RuntimeException.class) + @Test(expected=org.apache.cassandra.exceptions.InvalidRequestException.class) public void onCqlUpdateWithConditionsRejectGeneratedUpdatesForDifferentPartition() throws Exception { String cf = "cf" + System.nanoTime(); @@ -215,9 +211,7 @@ public class TriggersTest } } - // Unfortunately, an IRE thrown from StorageProxy.cas - // results in a RuntimeException from QueryProcessor.process - @Test(expected=RuntimeException.class) + @Test(expected=org.apache.cassandra.exceptions.InvalidRequestException.class) public void onCqlUpdateWithConditionsRejectGeneratedUpdatesForDifferentTable() throws Exception { String cf = "cf" + System.nanoTime(); @@ -283,6 +277,27 @@ public class TriggersTest } } + @Test(expected=org.apache.cassandra.exceptions.InvalidRequestException.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) + { + assertTrue(e.getMessage().equals(ErrorTrigger.MESSAGE)); + throw e; + } + finally + { + assertUpdateNotExecuted(cf, 11); + } + } + private void setupTableWithTrigger(String cf, Class<? extends ITrigger> triggerImpl) throws RequestExecutionException { @@ -352,4 +367,13 @@ public class TriggersTest return Collections.singletonList(update.build()); } } + + public static class ErrorTrigger implements ITrigger + { + public static final String MESSAGE = "Thrown by ErrorTrigger"; + public Collection<Mutation> augment(Partition partition) + { + throw new org.apache.cassandra.exceptions.InvalidRequestException(MESSAGE); + } + } }
