Repository: cassandra Updated Branches: refs/heads/trunk a9499e7df -> cc5128a02
Add CustomPayloadMirroringQueryHandler for driver testing patch by Adam Holmberg; reviewed by Sam Tunnicliffe for CASSANDRA-9212 Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/cc5128a0 Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/cc5128a0 Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/cc5128a0 Branch: refs/heads/trunk Commit: cc5128a02e01c3dad1f658f7dc6281e4f55eeb9a Parents: a9499e7 Author: Adam Holmberg <[email protected]> Authored: Mon Apr 27 21:32:24 2015 +0300 Committer: Aleksey Yeschenko <[email protected]> Committed: Mon Apr 27 21:32:24 2015 +0300 ---------------------------------------------------------------------- CHANGES.txt | 2 +- .../CustomPayloadMirroringQueryHandler.java | 74 ++++++++++++++++++++ .../org/apache/cassandra/transport/CBUtil.java | 8 +-- 3 files changed, 79 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/cc5128a0/CHANGES.txt ---------------------------------------------------------------------- diff --git a/CHANGES.txt b/CHANGES.txt index c422a70..ee17277 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -18,7 +18,7 @@ * Delay "node up" and "node added" notifications until native protocol server is started (CASSANDRA-8236) * Compressed Commit Log (CASSANDRA-6809) * Optimise IntervalTree (CASSANDRA-8988) - * Add a key-value payload for third party usage (CASSANDRA-8553) + * Add a key-value payload for third party usage (CASSANDRA-8553, 9212) * Bump metrics-reporter-config dependency for metrics 3.0 (CASSANDRA-8149) * Partition intra-cluster message streams by size, not type (CASSANDRA-8789) * Add WriteFailureException to native protocol, notify coordinator of http://git-wip-us.apache.org/repos/asf/cassandra/blob/cc5128a0/src/java/org/apache/cassandra/cql3/CustomPayloadMirroringQueryHandler.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/cql3/CustomPayloadMirroringQueryHandler.java b/src/java/org/apache/cassandra/cql3/CustomPayloadMirroringQueryHandler.java new file mode 100644 index 0000000..3930e9c --- /dev/null +++ b/src/java/org/apache/cassandra/cql3/CustomPayloadMirroringQueryHandler.java @@ -0,0 +1,74 @@ +/* + * 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.cql3; + +import java.util.Map; + +import org.apache.cassandra.cql3.statements.BatchStatement; +import org.apache.cassandra.cql3.statements.ParsedStatement; +import org.apache.cassandra.service.QueryState; +import org.apache.cassandra.transport.messages.ResultMessage; +import org.apache.cassandra.utils.MD5Digest; + +/** + * Custom QueryHandler that sends custom request payloads back with the result. + * Used to facilitate testing. + * Enabled with system property cassandra.custom_query_handler_class. + */ +public class CustomPayloadMirroringQueryHandler implements QueryHandler +{ + static QueryProcessor queryProcessor = QueryProcessor.instance; + + public ResultMessage process(String query, QueryState state, QueryOptions options, Map<String, byte[]> customPayload) + { + ResultMessage result = queryProcessor.process(query, state, options, customPayload); + result.setCustomPayload(customPayload); + return result; + } + + public ResultMessage.Prepared prepare(String query, QueryState state, Map<String, byte[]> customPayload) + { + ResultMessage.Prepared prepared = queryProcessor.prepare(query, state, customPayload); + prepared.setCustomPayload(customPayload); + return prepared; + } + + public ParsedStatement.Prepared getPrepared(MD5Digest id) + { + return queryProcessor.getPrepared(id); + } + + public ParsedStatement.Prepared getPreparedForThrift(Integer id) + { + return queryProcessor.getPreparedForThrift(id); + } + + public ResultMessage processPrepared(CQLStatement statement, QueryState state, QueryOptions options, Map<String, byte[]> customPayload) + { + ResultMessage result = queryProcessor.processPrepared(statement, state, options, customPayload); + result.setCustomPayload(customPayload); + return result; + } + + public ResultMessage processBatch(BatchStatement statement, QueryState state, BatchQueryOptions options, Map<String, byte[]> customPayload) + { + ResultMessage result = queryProcessor.processBatch(statement, state, options, customPayload); + result.setCustomPayload(customPayload); + return result; + } +} http://git-wip-us.apache.org/repos/asf/cassandra/blob/cc5128a0/src/java/org/apache/cassandra/transport/CBUtil.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/transport/CBUtil.java b/src/java/org/apache/cassandra/transport/CBUtil.java index 73df554..48beea0 100644 --- a/src/java/org/apache/cassandra/transport/CBUtil.java +++ b/src/java/org/apache/cassandra/transport/CBUtil.java @@ -46,7 +46,7 @@ import org.apache.cassandra.utils.ByteBufferUtil; /** * ByteBuf utility methods. * Note that contrarily to ByteBufferUtil, these method do "read" the - * ByteBuf advancing it's (read) position. They also write by + * ByteBuf advancing its (read) position. They also write by * advancing the write position. Functions are also provided to create * ByteBuf while avoiding copies. */ @@ -93,7 +93,7 @@ public abstract class CBUtil } catch (IndexOutOfBoundsException e) { - throw new ProtocolException("Not enough bytes to read an UTF8 serialized string preceded by it's 2 bytes length"); + throw new ProtocolException("Not enough bytes to read an UTF8 serialized string preceded by its 2 bytes length"); } } @@ -141,7 +141,7 @@ public abstract class CBUtil } catch (IndexOutOfBoundsException e) { - throw new ProtocolException("Not enough bytes to read an UTF8 serialized string preceded by it's 4 bytes length"); + throw new ProtocolException("Not enough bytes to read an UTF8 serialized string preceded by its 4 bytes length"); } } @@ -168,7 +168,7 @@ public abstract class CBUtil } catch (IndexOutOfBoundsException e) { - throw new ProtocolException("Not enough bytes to read a byte array preceded by it's 2 bytes length"); + throw new ProtocolException("Not enough bytes to read a byte array preceded by its 2 bytes length"); } }
