Repository: geode Updated Branches: refs/heads/feature/GEODE-2995 c7c1717d1 -> 02860bab2
GEODE-2995: Added Codec Registry Added translation service for Protobuf encoding type -> SerializationType Refactored unchecked Exceptions to checked Exceptions Project: http://git-wip-us.apache.org/repos/asf/geode/repo Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/02860bab Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/02860bab Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/02860bab Branch: refs/heads/feature/GEODE-2995 Commit: 02860bab21bcada50a18c4bf5224d0155b601600 Parents: c7c1717 Author: Udo Kohlmeyer <[email protected]> Authored: Tue Jun 13 16:11:02 2017 -0700 Committer: Udo Kohlmeyer <[email protected]> Committed: Tue Jun 13 16:11:02 2017 -0700 ---------------------------------------------------------------------- .../InvalidProtocolMessageException.java | 22 ++-- .../geode/protocol/handler/ProtocolHandler.java | 25 +++-- .../protobuf/ProtobufProtocolHandler.java | 22 ++-- .../protocol/operations/OperationHandler.java | 23 ++--- .../registry/OperationsHandlerRegistry.java | 27 +++-- ...rationHandlerAlreadyRegisteredException.java | 24 ++--- .../OperationHandlerNotRegisteredException.java | 27 ++--- .../geode/serialization/SerializationType.java | 5 +- .../apache/geode/serialization/TypeCodec.java | 23 ++--- ...codingTypeToSerializationTypeTranslator.java | 40 ++++++++ .../UnsupportedEncodingTypeException.java | 21 ++++ .../registry/SerializationCodecRegistry.java | 36 +++---- .../CodecAlreadyRegisteredForType.java | 23 ----- .../CodecAlreadyRegisteredForTypeException.java | 21 ++++ .../CodecNotRegisteredForTypeException.java | 27 ++--- .../geode/client/protocol/EncodingHandler.java | 23 ++--- .../protocol/EncodingHandlerRegistry.java | 26 +++-- .../geode/client/protocol/MessageUtil.java | 24 ++--- .../geode/client/protocol/OpsHandler.java | 26 +++-- .../geode/client/protocol/OpsProcessorTest.java | 100 +++++++++++++------ .../ProtobufRequestOperationParser.java | 28 +++--- .../ProtobufProtocolHandlerJUnitTest.java | 88 ++++++++++++++++ .../handler/ProtobufProtocolHandlerTest.java | 87 ---------------- .../OperationsHandlerRegistryJUnitTest.java | 23 +++-- ...eToSerializationTypeTranslatorJUnitTest.java | 65 ++++++++++++ .../registry/CodecRegistryJUnitTest.java | 47 ++++----- 26 files changed, 528 insertions(+), 375 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/geode/blob/02860bab/geode-protobuf/src/main/java/org/apache/geode/protocol/exception/InvalidProtocolMessageException.java ---------------------------------------------------------------------- diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/exception/InvalidProtocolMessageException.java b/geode-protobuf/src/main/java/org/apache/geode/protocol/exception/InvalidProtocolMessageException.java index ef3d7bb..8f73f57 100644 --- a/geode-protobuf/src/main/java/org/apache/geode/protocol/exception/InvalidProtocolMessageException.java +++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/exception/InvalidProtocolMessageException.java @@ -1,18 +1,16 @@ /* - * 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 + * 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 + * 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. + * 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.geode.protocol.exception; http://git-wip-us.apache.org/repos/asf/geode/blob/02860bab/geode-protobuf/src/main/java/org/apache/geode/protocol/handler/ProtocolHandler.java ---------------------------------------------------------------------- diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/handler/ProtocolHandler.java b/geode-protobuf/src/main/java/org/apache/geode/protocol/handler/ProtocolHandler.java index 525f232..4947a0a 100644 --- a/geode-protobuf/src/main/java/org/apache/geode/protocol/handler/ProtocolHandler.java +++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/handler/ProtocolHandler.java @@ -1,18 +1,16 @@ /* - * 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 + * 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 + * 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. + * 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.geode.protocol.handler; @@ -22,7 +20,8 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -public interface ProtocolHandler <T> { +public interface ProtocolHandler<T> { T deserialize(InputStream inputStream) throws InvalidProtocolMessageException; + void serialize(T inputMessage, OutputStream outputStream) throws IOException; } http://git-wip-us.apache.org/repos/asf/geode/blob/02860bab/geode-protobuf/src/main/java/org/apache/geode/protocol/handler/protobuf/ProtobufProtocolHandler.java ---------------------------------------------------------------------- diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/handler/protobuf/ProtobufProtocolHandler.java b/geode-protobuf/src/main/java/org/apache/geode/protocol/handler/protobuf/ProtobufProtocolHandler.java index 84fc50f..f8c2abd 100644 --- a/geode-protobuf/src/main/java/org/apache/geode/protocol/handler/protobuf/ProtobufProtocolHandler.java +++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/handler/protobuf/ProtobufProtocolHandler.java @@ -1,18 +1,16 @@ /* - * 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 + * 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 + * 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. + * 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.geode.protocol.handler.protobuf; http://git-wip-us.apache.org/repos/asf/geode/blob/02860bab/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/OperationHandler.java ---------------------------------------------------------------------- diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/OperationHandler.java b/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/OperationHandler.java index 793fcb6..c494855 100644 --- a/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/OperationHandler.java +++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/OperationHandler.java @@ -1,20 +1,19 @@ /* - * 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 + * 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 + * 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. + * 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.geode.protocol.operations; public interface OperationHandler<T> { + Object process(Object encodingHandlerRegistry, T request); } http://git-wip-us.apache.org/repos/asf/geode/blob/02860bab/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/registry/OperationsHandlerRegistry.java ---------------------------------------------------------------------- diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/registry/OperationsHandlerRegistry.java b/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/registry/OperationsHandlerRegistry.java index 0a39b5e..2e9b40a 100644 --- a/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/registry/OperationsHandlerRegistry.java +++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/registry/OperationsHandlerRegistry.java @@ -1,18 +1,16 @@ /* - * 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 + * 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 + * 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. + * 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.geode.protocol.operations.registry; @@ -25,7 +23,8 @@ import java.util.HashMap; public class OperationsHandlerRegistry { private HashMap<Integer, OperationHandler> registeredOperations = new HashMap<>(); - public OperationHandler getOperationHandlerForOperationId(int operationCode) { + public OperationHandler getOperationHandlerForOperationId(int operationCode) + throws OperationHandlerNotRegisteredException { OperationHandler operationHandler = registeredOperations.get(operationCode); if (operationHandler == null) { throw new OperationHandlerNotRegisteredException( @@ -35,7 +34,7 @@ public class OperationsHandlerRegistry { } public synchronized void registerOperationHandlerForOperationId(int operationCode, - OperationHandler operationHandler) { + OperationHandler operationHandler) throws OperationHandlerAlreadyRegisteredException { if (registeredOperations.containsKey(operationCode)) { throw new OperationHandlerAlreadyRegisteredException( "An operation handler for operationCode: " + operationCode http://git-wip-us.apache.org/repos/asf/geode/blob/02860bab/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/registry/exception/OperationHandlerAlreadyRegisteredException.java ---------------------------------------------------------------------- diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/registry/exception/OperationHandlerAlreadyRegisteredException.java b/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/registry/exception/OperationHandlerAlreadyRegisteredException.java index 7066ee3..1f42c10 100644 --- a/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/registry/exception/OperationHandlerAlreadyRegisteredException.java +++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/registry/exception/OperationHandlerAlreadyRegisteredException.java @@ -1,22 +1,20 @@ /* - * 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 + * 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 + * 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. + * 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.geode.protocol.operations.registry.exception; -public class OperationHandlerAlreadyRegisteredException extends RuntimeException { +public class OperationHandlerAlreadyRegisteredException extends Exception { public OperationHandlerAlreadyRegisteredException(String message) { super(message); } http://git-wip-us.apache.org/repos/asf/geode/blob/02860bab/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/registry/exception/OperationHandlerNotRegisteredException.java ---------------------------------------------------------------------- diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/registry/exception/OperationHandlerNotRegisteredException.java b/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/registry/exception/OperationHandlerNotRegisteredException.java index d86cac8..f83e1b3 100644 --- a/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/registry/exception/OperationHandlerNotRegisteredException.java +++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/registry/exception/OperationHandlerNotRegisteredException.java @@ -1,25 +1,20 @@ /* - * 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 + * 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 + * 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. + * 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.geode.protocol.operations.registry.exception; -/** - * Created by ukohlmeyer on 6/13/17. - */ -public class OperationHandlerNotRegisteredException extends RuntimeException { +public class OperationHandlerNotRegisteredException extends Exception { public OperationHandlerNotRegisteredException(String message) { super(message); } http://git-wip-us.apache.org/repos/asf/geode/blob/02860bab/geode-protobuf/src/main/java/org/apache/geode/serialization/SerializationType.java ---------------------------------------------------------------------- diff --git a/geode-protobuf/src/main/java/org/apache/geode/serialization/SerializationType.java b/geode-protobuf/src/main/java/org/apache/geode/serialization/SerializationType.java index ada0674..01e691b 100644 --- a/geode-protobuf/src/main/java/org/apache/geode/serialization/SerializationType.java +++ b/geode-protobuf/src/main/java/org/apache/geode/serialization/SerializationType.java @@ -11,7 +11,10 @@ public enum SerializationType { BYTE(byte.class), SHORT(short.class), LONG(long.class), - JSON(PdxInstance.class); + JSON(PdxInstance.class), + BOOLEAN(boolean.class), + FLOAT(float.class), + DOUBLE(double.class); private static final Charset UTF8 = Charset.forName("UTF-8"); public final Class klass; http://git-wip-us.apache.org/repos/asf/geode/blob/02860bab/geode-protobuf/src/main/java/org/apache/geode/serialization/TypeCodec.java ---------------------------------------------------------------------- diff --git a/geode-protobuf/src/main/java/org/apache/geode/serialization/TypeCodec.java b/geode-protobuf/src/main/java/org/apache/geode/serialization/TypeCodec.java index e756d0a..a4eec96 100644 --- a/geode-protobuf/src/main/java/org/apache/geode/serialization/TypeCodec.java +++ b/geode-protobuf/src/main/java/org/apache/geode/serialization/TypeCodec.java @@ -1,22 +1,21 @@ /* - * 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 + * 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 + * 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. + * 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.geode.serialization; public interface TypeCodec<T> { T decode(byte[] incoming); + byte[] encode(T incoming); } http://git-wip-us.apache.org/repos/asf/geode/blob/02860bab/geode-protobuf/src/main/java/org/apache/geode/serialization/protobuf/translation/EncodingTypeToSerializationTypeTranslator.java ---------------------------------------------------------------------- diff --git a/geode-protobuf/src/main/java/org/apache/geode/serialization/protobuf/translation/EncodingTypeToSerializationTypeTranslator.java b/geode-protobuf/src/main/java/org/apache/geode/serialization/protobuf/translation/EncodingTypeToSerializationTypeTranslator.java new file mode 100644 index 0000000..cae2b20 --- /dev/null +++ b/geode-protobuf/src/main/java/org/apache/geode/serialization/protobuf/translation/EncodingTypeToSerializationTypeTranslator.java @@ -0,0 +1,40 @@ +/* + * 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.geode.serialization.protobuf.translation; + +import org.apache.geode.protocol.protobuf.BasicTypes; +import org.apache.geode.serialization.SerializationType; +import org.apache.geode.serialization.protobuf.translation.exception.UnsupportedEncodingTypeException; + +public class EncodingTypeToSerializationTypeTranslator { + public SerializationType getSerializationTypeForEncodingType(BasicTypes.EncodingType encodingType) + throws UnsupportedEncodingTypeException { + switch (encodingType) { + case INT: return SerializationType.INT; + case BYTE: return SerializationType.BYTE; + case JSON: return SerializationType.JSON; + case LONG: return SerializationType.LONG; + case FLOAT: return SerializationType.FLOAT; + case SHORT: return SerializationType.SHORT; + case BINARY: return SerializationType.BYTE_BLOB; + case DOUBLE: return SerializationType.DOUBLE; + case STRING: return SerializationType.STRING; + case BOOLEAN: return SerializationType.BOOLEAN; + default: + throw new UnsupportedEncodingTypeException( + "No serialization type found for protobuf encoding type: " + encodingType); + } + } +} http://git-wip-us.apache.org/repos/asf/geode/blob/02860bab/geode-protobuf/src/main/java/org/apache/geode/serialization/protobuf/translation/exception/UnsupportedEncodingTypeException.java ---------------------------------------------------------------------- diff --git a/geode-protobuf/src/main/java/org/apache/geode/serialization/protobuf/translation/exception/UnsupportedEncodingTypeException.java b/geode-protobuf/src/main/java/org/apache/geode/serialization/protobuf/translation/exception/UnsupportedEncodingTypeException.java new file mode 100644 index 0000000..ad01eac --- /dev/null +++ b/geode-protobuf/src/main/java/org/apache/geode/serialization/protobuf/translation/exception/UnsupportedEncodingTypeException.java @@ -0,0 +1,21 @@ +/* + * 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.geode.serialization.protobuf.translation.exception; + +public class UnsupportedEncodingTypeException extends Exception { + public UnsupportedEncodingTypeException(String message) { + super(message); + } +} http://git-wip-us.apache.org/repos/asf/geode/blob/02860bab/geode-protobuf/src/main/java/org/apache/geode/serialization/registry/SerializationCodecRegistry.java ---------------------------------------------------------------------- diff --git a/geode-protobuf/src/main/java/org/apache/geode/serialization/registry/SerializationCodecRegistry.java b/geode-protobuf/src/main/java/org/apache/geode/serialization/registry/SerializationCodecRegistry.java index b88b186..278770b 100644 --- a/geode-protobuf/src/main/java/org/apache/geode/serialization/registry/SerializationCodecRegistry.java +++ b/geode-protobuf/src/main/java/org/apache/geode/serialization/registry/SerializationCodecRegistry.java @@ -1,24 +1,22 @@ /* - * 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 + * 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 + * 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. + * 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.geode.serialization.registry; import org.apache.geode.serialization.SerializationType; import org.apache.geode.serialization.TypeCodec; -import org.apache.geode.serialization.registry.exception.CodecAlreadyRegisteredForType; +import org.apache.geode.serialization.registry.exception.CodecAlreadyRegisteredForTypeException; import org.apache.geode.serialization.registry.exception.CodecNotRegisteredForTypeException; import java.util.HashMap; @@ -26,9 +24,11 @@ import java.util.HashMap; public class SerializationCodecRegistry { private HashMap<SerializationType, TypeCodec> codecRegistry = new HashMap<>(); - public synchronized void register(SerializationType serializationType, TypeCodec<?> typeCodec) { + public synchronized void register(SerializationType serializationType, TypeCodec<?> typeCodec) + throws CodecAlreadyRegisteredForTypeException { if (codecRegistry.containsKey(serializationType)) { - throw new CodecAlreadyRegisteredForType("There is already a codec registered for type: " + serializationType); + throw new CodecAlreadyRegisteredForTypeException( + "There is already a codec registered for type: " + serializationType); } codecRegistry.put(serializationType, typeCodec); } @@ -37,10 +37,12 @@ public class SerializationCodecRegistry { return codecRegistry.size(); } - public TypeCodec getCodecForType(SerializationType serializationType) { + public TypeCodec getCodecForType(SerializationType serializationType) + throws CodecNotRegisteredForTypeException { TypeCodec typeCodec = codecRegistry.get(serializationType); if (typeCodec == null) { - throw new CodecNotRegisteredForTypeException("There is no codec registered for type: " + serializationType); + throw new CodecNotRegisteredForTypeException( + "There is no codec registered for type: " + serializationType); } return typeCodec; } http://git-wip-us.apache.org/repos/asf/geode/blob/02860bab/geode-protobuf/src/main/java/org/apache/geode/serialization/registry/exception/CodecAlreadyRegisteredForType.java ---------------------------------------------------------------------- diff --git a/geode-protobuf/src/main/java/org/apache/geode/serialization/registry/exception/CodecAlreadyRegisteredForType.java b/geode-protobuf/src/main/java/org/apache/geode/serialization/registry/exception/CodecAlreadyRegisteredForType.java deleted file mode 100644 index 34c5202..0000000 --- a/geode-protobuf/src/main/java/org/apache/geode/serialization/registry/exception/CodecAlreadyRegisteredForType.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * 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.geode.serialization.registry.exception; - -public class CodecAlreadyRegisteredForType extends RuntimeException { - public CodecAlreadyRegisteredForType(String message) { - super(message); - } -} http://git-wip-us.apache.org/repos/asf/geode/blob/02860bab/geode-protobuf/src/main/java/org/apache/geode/serialization/registry/exception/CodecAlreadyRegisteredForTypeException.java ---------------------------------------------------------------------- diff --git a/geode-protobuf/src/main/java/org/apache/geode/serialization/registry/exception/CodecAlreadyRegisteredForTypeException.java b/geode-protobuf/src/main/java/org/apache/geode/serialization/registry/exception/CodecAlreadyRegisteredForTypeException.java new file mode 100644 index 0000000..678d374 --- /dev/null +++ b/geode-protobuf/src/main/java/org/apache/geode/serialization/registry/exception/CodecAlreadyRegisteredForTypeException.java @@ -0,0 +1,21 @@ +/* + * 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.geode.serialization.registry.exception; + +public class CodecAlreadyRegisteredForTypeException extends Exception { + public CodecAlreadyRegisteredForTypeException(String message) { + super(message); + } +} http://git-wip-us.apache.org/repos/asf/geode/blob/02860bab/geode-protobuf/src/main/java/org/apache/geode/serialization/registry/exception/CodecNotRegisteredForTypeException.java ---------------------------------------------------------------------- diff --git a/geode-protobuf/src/main/java/org/apache/geode/serialization/registry/exception/CodecNotRegisteredForTypeException.java b/geode-protobuf/src/main/java/org/apache/geode/serialization/registry/exception/CodecNotRegisteredForTypeException.java index 8d895a1..a1a6408 100644 --- a/geode-protobuf/src/main/java/org/apache/geode/serialization/registry/exception/CodecNotRegisteredForTypeException.java +++ b/geode-protobuf/src/main/java/org/apache/geode/serialization/registry/exception/CodecNotRegisteredForTypeException.java @@ -1,25 +1,20 @@ /* - * 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 + * 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 + * 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. + * 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.geode.serialization.registry.exception; -/** - * Created by ukohlmeyer on 6/13/17. - */ -public class CodecNotRegisteredForTypeException extends RuntimeException { +public class CodecNotRegisteredForTypeException extends Exception { public CodecNotRegisteredForTypeException(String message) { super(message); } http://git-wip-us.apache.org/repos/asf/geode/blob/02860bab/geode-protobuf/src/test/java/org/apache/geode/client/protocol/EncodingHandler.java ---------------------------------------------------------------------- diff --git a/geode-protobuf/src/test/java/org/apache/geode/client/protocol/EncodingHandler.java b/geode-protobuf/src/test/java/org/apache/geode/client/protocol/EncodingHandler.java index 8d8830a..bc5dab3 100644 --- a/geode-protobuf/src/test/java/org/apache/geode/client/protocol/EncodingHandler.java +++ b/geode-protobuf/src/test/java/org/apache/geode/client/protocol/EncodingHandler.java @@ -1,22 +1,21 @@ /* - * 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 + * 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 + * 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. + * 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.geode.client.protocol; public interface EncodingHandler<T> { T deserialze(byte[] incoming); + byte[] serialize(T incoming); } http://git-wip-us.apache.org/repos/asf/geode/blob/02860bab/geode-protobuf/src/test/java/org/apache/geode/client/protocol/EncodingHandlerRegistry.java ---------------------------------------------------------------------- diff --git a/geode-protobuf/src/test/java/org/apache/geode/client/protocol/EncodingHandlerRegistry.java b/geode-protobuf/src/test/java/org/apache/geode/client/protocol/EncodingHandlerRegistry.java index 44dee6a..8bc35a5 100644 --- a/geode-protobuf/src/test/java/org/apache/geode/client/protocol/EncodingHandlerRegistry.java +++ b/geode-protobuf/src/test/java/org/apache/geode/client/protocol/EncodingHandlerRegistry.java @@ -1,23 +1,21 @@ /* - * 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 + * 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 + * 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. + * 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.geode.client.protocol; -import com.sun.xml.internal.bind.v2.runtime.output.Encoded; +import org.apache.geode.serialization.SerializationType; public interface EncodingHandlerRegistry { - EncodingHandler getEncodingHandlerForType(Class klass) + EncodingHandler getEncodingHandlerForType(SerializationType serializationType); } http://git-wip-us.apache.org/repos/asf/geode/blob/02860bab/geode-protobuf/src/test/java/org/apache/geode/client/protocol/MessageUtil.java ---------------------------------------------------------------------- diff --git a/geode-protobuf/src/test/java/org/apache/geode/client/protocol/MessageUtil.java b/geode-protobuf/src/test/java/org/apache/geode/client/protocol/MessageUtil.java index ec07355..c830b01 100644 --- a/geode-protobuf/src/test/java/org/apache/geode/client/protocol/MessageUtil.java +++ b/geode-protobuf/src/test/java/org/apache/geode/client/protocol/MessageUtil.java @@ -1,18 +1,16 @@ /* - * 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 + * 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 + * 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. + * 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.geode.client.protocol; @@ -20,7 +18,7 @@ import org.apache.geode.protocol.protobuf.ClientProtocol; import org.apache.geode.protocol.protobuf.RegionAPI; public class MessageUtil { - public static ClientProtocol.Message createGetRequestMessage(){ + public static ClientProtocol.Message createGetRequestMessage() { ClientProtocol.Message.Builder messageBuilder = ClientProtocol.Message.newBuilder(); messageBuilder.setMessageHeader(getMessageHeaderBuilder()); ClientProtocol.Request.Builder requestBuilder = getRequestBuilder(); http://git-wip-us.apache.org/repos/asf/geode/blob/02860bab/geode-protobuf/src/test/java/org/apache/geode/client/protocol/OpsHandler.java ---------------------------------------------------------------------- diff --git a/geode-protobuf/src/test/java/org/apache/geode/client/protocol/OpsHandler.java b/geode-protobuf/src/test/java/org/apache/geode/client/protocol/OpsHandler.java index 864b024..73fc370 100644 --- a/geode-protobuf/src/test/java/org/apache/geode/client/protocol/OpsHandler.java +++ b/geode-protobuf/src/test/java/org/apache/geode/client/protocol/OpsHandler.java @@ -1,24 +1,22 @@ /* - * 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 + * 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 + * 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. + * 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.geode.client.protocol; /** * Created by ukohlmeyer on 6/12/17. */ -public interface OpsHandler<Req,Resp> { - public Resp process(Req request); +public interface OpsHandler<Req, Resp> { + Resp process(EncodingHandlerRegistry encodingHandlerRegistry, Req request); } http://git-wip-us.apache.org/repos/asf/geode/blob/02860bab/geode-protobuf/src/test/java/org/apache/geode/client/protocol/OpsProcessorTest.java ---------------------------------------------------------------------- diff --git a/geode-protobuf/src/test/java/org/apache/geode/client/protocol/OpsProcessorTest.java b/geode-protobuf/src/test/java/org/apache/geode/client/protocol/OpsProcessorTest.java index ba8490b..ed28948 100644 --- a/geode-protobuf/src/test/java/org/apache/geode/client/protocol/OpsProcessorTest.java +++ b/geode-protobuf/src/test/java/org/apache/geode/client/protocol/OpsProcessorTest.java @@ -1,66 +1,108 @@ /* - * 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 + * 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 + * 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. + * 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.geode.client.protocol; + import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import com.google.protobuf.ByteString; +import org.apache.geode.protocol.operations.OperationHandler; +import org.apache.geode.protocol.operations.registry.OperationsHandlerRegistry; +import org.apache.geode.protocol.operations.registry.exception.OperationHandlerNotRegisteredException; import org.apache.geode.protocol.protobuf.BasicTypes; import org.apache.geode.protocol.protobuf.ClientProtocol; import org.apache.geode.protocol.protobuf.RegionAPI; +import org.apache.geode.serialization.SerializationType; import org.junit.Assert; import org.junit.Test; public class OpsProcessorTest { @Test public void testOpsProcessor() { - OpsHandlerRegistry registryStub = mock(OpsHandlerRegistry.class); - OpsHandler operationHandlerStub = mock(OpsHandler.class); + OperationsHandlerRegistry opsHandlerRegistry = mock(OperationsHandlerRegistry.class); + OperationHandler operationHandlerStub = mock(OperationHandler.class); EncodingHandlerRegistry encodingHandlerRegistry = mock(EncodingHandlerRegistry.class); EncodingHandler encodingHandler = mock(EncodingHandler.class); + when(encodingHandlerRegistry.getEncodingHandlerForType(SerializationType.STRING)) + .thenReturn(new EncodingHandler() { + @Override + public Object deserialze(byte[] incoming) { + return new String(incoming); + } + + @Override + public byte[] serialize(Object incoming) { + return ((String) incoming).getBytes(); + } + }); - ClientProtocol.Request messageRequest = ClientProtocol.Request.newBuilder().build(); - String expectedResponse = "10"; - when(registryStub.getOpsHandler(2)).thenReturn(operationHandlerStub); - when(operationHandlerStub.process(messageRequest)).thenReturn(expectedResponse); + ClientProtocol.Request messageRequest = ClientProtocol.Request.newBuilder() + .setGetRequest(RegionAPI.GetRequest.newBuilder()).build(); + RegionAPI.GetResponse expectedResponse = getGetResponse(encodingHandlerRegistry); + try { + when(opsHandlerRegistry.getOperationHandlerForOperationId(2)).thenReturn(operationHandlerStub); + } catch (OperationHandlerNotRegisteredException e) { + e.printStackTrace(); + } + when(operationHandlerStub.process(encodingHandlerRegistry, + ProtobufRequestOperationParser.getRequestForOperationTypeID(messageRequest))) + .thenReturn(expectedResponse); - OpsProcessor processor = new OpsProcessor(registryStub); + OpsProcessor processor = new OpsProcessor(opsHandlerRegistry, encodingHandlerRegistry); ClientProtocol.Response response = processor.process(messageRequest); Assert.assertEquals(expectedResponse, response.getGetResponse()); + + } + + private RegionAPI.GetResponse getGetResponse(EncodingHandlerRegistry encodingHandlerRegistry) { + RegionAPI.GetResponse.Builder getResponseBuilder = RegionAPI.GetResponse.newBuilder(); + BasicTypes.EncodedValue.Builder encodedValueBuilder = BasicTypes.EncodedValue.newBuilder(); + EncodingHandler encodingHandler = + encodingHandlerRegistry.getEncodingHandlerForType(SerializationType.STRING); + byte[] serializedValue = encodingHandler.serialize("10"); + encodedValueBuilder.setValue(ByteString.copyFrom(serializedValue)); + encodedValueBuilder.setEncodingType(BasicTypes.EncodingType.STRING); + getResponseBuilder.setResult(encodedValueBuilder); + return getResponseBuilder.build(); } private class OpsProcessor { - private OpsHandlerRegistry opsHandlerRegistry; - private EncodingHandler encodingHandler; + private final OperationsHandlerRegistry opsHandlerRegistry; + private final EncodingHandlerRegistry encodingHandlerRegistry; - public OpsProcessor(OpsHandlerRegistry opsHandlerRegistry,EncodingHandler encodingHandler) { + public OpsProcessor(OperationsHandlerRegistry opsHandlerRegistry, + EncodingHandlerRegistry encodingHandlerRegistry) { this.opsHandlerRegistry = opsHandlerRegistry; + this.encodingHandlerRegistry = encodingHandlerRegistry; } public ClientProtocol.Response process(ClientProtocol.Request request) { - OpsHandler<Object, Object> opsHandler = opsHandlerRegistry.getOpsHandler(2); - ClientProtocol.Response.Builder responseBuilder = ClientProtocol.Response.newBuilder(); - Object rawResponse = opsHandler.process(request); - BasicTypes.EncodedValue.Builder encodedValueBuilder = BasicTypes.EncodedValue.newBuilder(); - encodedValueBuilder.setValue(ByteString.copyFrom(rawResponse.getBytes())); - responseBuilder.setGetResponse(RegionAPI.GetResponse.newBuilder().setResult()) + OperationHandler opsHandler = null; + try { + opsHandler = opsHandlerRegistry.getOperationHandlerForOperationId(2); + } catch (OperationHandlerNotRegisteredException e) { + e.printStackTrace(); + } + + Object responseMessage = opsHandler.process(encodingHandlerRegistry, + ProtobufRequestOperationParser.getRequestForOperationTypeID(request)); + return ClientProtocol.Response.newBuilder() + .setGetResponse((RegionAPI.GetResponse) responseMessage).build(); } } -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/geode/blob/02860bab/geode-protobuf/src/test/java/org/apache/geode/client/protocol/ProtobufRequestOperationParser.java ---------------------------------------------------------------------- diff --git a/geode-protobuf/src/test/java/org/apache/geode/client/protocol/ProtobufRequestOperationParser.java b/geode-protobuf/src/test/java/org/apache/geode/client/protocol/ProtobufRequestOperationParser.java index 9f04fcb..7eeff02 100644 --- a/geode-protobuf/src/test/java/org/apache/geode/client/protocol/ProtobufRequestOperationParser.java +++ b/geode-protobuf/src/test/java/org/apache/geode/client/protocol/ProtobufRequestOperationParser.java @@ -1,18 +1,16 @@ /* - * 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 + * 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 + * 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. + * 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.geode.client.protocol; @@ -21,8 +19,10 @@ import org.apache.geode.protocol.protobuf.ClientProtocol; class ProtobufRequestOperationParser { static Object getRequestForOperationTypeID(ClientProtocol.Request request) { switch (request.getRequestAPICase()) { - case PUTREQUEST: return request.getPutRequest(); - case GETREQUEST: return request.getGetRequest(); + case PUTREQUEST: + return request.getPutRequest(); + case GETREQUEST: + return request.getGetRequest(); default: throw new RuntimeException( "Unknown request type: " + request.getRequestAPICase().getNumber()); http://git-wip-us.apache.org/repos/asf/geode/blob/02860bab/geode-protobuf/src/test/java/org/apache/geode/protocol/handler/ProtobufProtocolHandlerJUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-protobuf/src/test/java/org/apache/geode/protocol/handler/ProtobufProtocolHandlerJUnitTest.java b/geode-protobuf/src/test/java/org/apache/geode/protocol/handler/ProtobufProtocolHandlerJUnitTest.java new file mode 100644 index 0000000..21c3107 --- /dev/null +++ b/geode-protobuf/src/test/java/org/apache/geode/protocol/handler/ProtobufProtocolHandlerJUnitTest.java @@ -0,0 +1,88 @@ +/* + * 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.geode.protocol.handler; + +import org.apache.geode.client.protocol.MessageUtil; +import org.apache.geode.protocol.exception.InvalidProtocolMessageException; +import org.apache.geode.protocol.handler.ProtocolHandler; +import org.apache.geode.protocol.handler.protobuf.ProtobufProtocolHandler; +import org.apache.geode.protocol.protobuf.ClientProtocol; +import org.apache.geode.test.junit.categories.UnitTest; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.ServiceLoader; + +@Category(UnitTest.class) +public class ProtobufProtocolHandlerJUnitTest { + private ProtocolHandler<ClientProtocol.Message> protocolHandler; + + @Before + public void startup() { + ServiceLoader<ProtocolHandler> serviceLoader = ServiceLoader.load(ProtocolHandler.class); + for (ProtocolHandler protocolHandler : serviceLoader) { + if (protocolHandler instanceof ProtobufProtocolHandler) { + this.protocolHandler = protocolHandler; + } + } + } + + @Test + public void testDeserializeByteArrayToMessage() + throws IOException, InvalidProtocolMessageException { + ClientProtocol.Message expectedRequestMessage = MessageUtil.createGetRequestMessage(); + + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + + expectedRequestMessage.writeDelimitedTo(byteArrayOutputStream); + InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray()); + + ClientProtocol.Message actualMessage = protocolHandler.deserialize(inputStream); + Assert.assertEquals(expectedRequestMessage, actualMessage); + } + + @Test + public void testDeserializeInvalidByteThrowsException() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + byteArrayOutputStream.write("Some incorrect byte array".getBytes()); + InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray()); + + boolean caughtException = false; + try { + protocolHandler.deserialize(inputStream); + } catch (InvalidProtocolMessageException e) { + caughtException = true; + } + Assert.assertTrue(caughtException); + } + + @Test + public void testSerializeMessageToByteArray() throws IOException { + ClientProtocol.Message message = MessageUtil.createGetRequestMessage(); + ByteArrayOutputStream expectedByteArrayOutputStream = new ByteArrayOutputStream(); + message.writeDelimitedTo(expectedByteArrayOutputStream); + byte[] expectedByteArray = expectedByteArrayOutputStream.toByteArray(); + + ByteArrayOutputStream actualByteArrayOutputStream = new ByteArrayOutputStream(); + protocolHandler.serialize(message, actualByteArrayOutputStream); + Assert.assertArrayEquals(expectedByteArray, actualByteArrayOutputStream.toByteArray()); + } +} http://git-wip-us.apache.org/repos/asf/geode/blob/02860bab/geode-protobuf/src/test/java/org/apache/geode/protocol/handler/ProtobufProtocolHandlerTest.java ---------------------------------------------------------------------- diff --git a/geode-protobuf/src/test/java/org/apache/geode/protocol/handler/ProtobufProtocolHandlerTest.java b/geode-protobuf/src/test/java/org/apache/geode/protocol/handler/ProtobufProtocolHandlerTest.java deleted file mode 100644 index e8ffd87..0000000 --- a/geode-protobuf/src/test/java/org/apache/geode/protocol/handler/ProtobufProtocolHandlerTest.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * 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.geode.protocol.handler; - -import org.apache.geode.client.protocol.MessageUtil; -import org.apache.geode.protocol.exception.InvalidProtocolMessageException; -import org.apache.geode.protocol.handler.ProtocolHandler; -import org.apache.geode.protocol.handler.protobuf.ProtobufProtocolHandler; -import org.apache.geode.protocol.protobuf.ClientProtocol; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.ServiceLoader; - -public class ProtobufProtocolHandlerTest { - private ProtocolHandler<ClientProtocol.Message> protocolHandler; - - @Before - public void startup() { - ServiceLoader<ProtocolHandler> serviceLoader = ServiceLoader.load(ProtocolHandler.class); - for (ProtocolHandler protocolHandler : serviceLoader) { - if (protocolHandler instanceof ProtobufProtocolHandler) { - this.protocolHandler = protocolHandler; - } - } - } - - @Test - public void testDeserializeByteArrayToMessage() - throws IOException, InvalidProtocolMessageException { - ClientProtocol.Message expectedRequestMessage = MessageUtil.createGetRequestMessage(); - - ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); - - expectedRequestMessage.writeDelimitedTo(byteArrayOutputStream); - InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray()); - - ClientProtocol.Message actualMessage = protocolHandler.deserialize(inputStream); - Assert.assertEquals(expectedRequestMessage, actualMessage); - } - - @Test - public void testDeserializeInvalidByteThrowsException() throws IOException { - ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); - byteArrayOutputStream.write("Some incorrect byte array".getBytes()); - InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray()); - - boolean caughtException = false; - try { - protocolHandler.deserialize(inputStream); - } catch (InvalidProtocolMessageException e) { - caughtException = true; - } - Assert.assertTrue(caughtException); - } - - @Test - public void testSerializeMessageToByteArray() throws IOException { - ClientProtocol.Message message = MessageUtil.createGetRequestMessage(); - ByteArrayOutputStream expectedByteArrayOutputStream = new ByteArrayOutputStream(); - message.writeDelimitedTo(expectedByteArrayOutputStream); - byte[] expectedByteArray = expectedByteArrayOutputStream.toByteArray(); - - ByteArrayOutputStream actualByteArrayOutputStream = new ByteArrayOutputStream(); - protocolHandler.serialize(message, actualByteArrayOutputStream); - Assert.assertArrayEquals(expectedByteArray,actualByteArrayOutputStream.toByteArray()); - } -} http://git-wip-us.apache.org/repos/asf/geode/blob/02860bab/geode-protobuf/src/test/java/org/apache/geode/protocol/operations/registry/OperationsHandlerRegistryJUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-protobuf/src/test/java/org/apache/geode/protocol/operations/registry/OperationsHandlerRegistryJUnitTest.java b/geode-protobuf/src/test/java/org/apache/geode/protocol/operations/registry/OperationsHandlerRegistryJUnitTest.java index 66ee8d1..9a81706 100644 --- a/geode-protobuf/src/test/java/org/apache/geode/protocol/operations/registry/OperationsHandlerRegistryJUnitTest.java +++ b/geode-protobuf/src/test/java/org/apache/geode/protocol/operations/registry/OperationsHandlerRegistryJUnitTest.java @@ -22,21 +22,23 @@ public class OperationsHandlerRegistryJUnitTest { } @Test - public void testAddOperationsHandlerForOperationType() { - operationsHandlerRegistry - .registerOperationHandlerForOperationId(5, new DummyOperationHandler()); + public void testAddOperationsHandlerForOperationType() + throws OperationHandlerAlreadyRegisteredException { + operationsHandlerRegistry.registerOperationHandlerForOperationId(5, + new DummyOperationHandler()); assertEquals(1, operationsHandlerRegistry.getRegisteredOperationHandlersCount()); } @Test - public void testAddingDuplicateOperationsHandlerForOperationType_ThrowsException() { + public void testAddingDuplicateOperationsHandlerForOperationType_ThrowsException() + throws OperationHandlerAlreadyRegisteredException, OperationHandlerNotRegisteredException { DummyOperationHandler expectedOperationHandler = new DummyOperationHandler(); operationsHandlerRegistry.registerOperationHandlerForOperationId(5, expectedOperationHandler); assertEquals(1, operationsHandlerRegistry.getRegisteredOperationHandlersCount()); boolean exceptionCaught = false; try { - operationsHandlerRegistry - .registerOperationHandlerForOperationId(5, new DummyOperationHandler()); + operationsHandlerRegistry.registerOperationHandlerForOperationId(5, + new DummyOperationHandler()); } catch (OperationHandlerAlreadyRegisteredException e) { exceptionCaught = true; } @@ -47,7 +49,8 @@ public class OperationsHandlerRegistryJUnitTest { } @Test - public void testGetOperationsHandlerForOperationType() { + public void testGetOperationsHandlerForOperationType() + throws OperationHandlerAlreadyRegisteredException, OperationHandlerNotRegisteredException { DummyOperationHandler expectedOperationHandler = new DummyOperationHandler(); operationsHandlerRegistry.registerOperationHandlerForOperationId(5, expectedOperationHandler); OperationHandler operationHandler = @@ -68,7 +71,11 @@ public class OperationsHandlerRegistryJUnitTest { private class DummyOperationHandler implements OperationHandler { + @Override + public Object process(Object encodingHandlerRegistry, Object request) { + return null; + } } -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/geode/blob/02860bab/geode-protobuf/src/test/java/org/apache/geode/serialization/protobuf/translation/EncodingTypeToSerializationTypeTranslatorJUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-protobuf/src/test/java/org/apache/geode/serialization/protobuf/translation/EncodingTypeToSerializationTypeTranslatorJUnitTest.java b/geode-protobuf/src/test/java/org/apache/geode/serialization/protobuf/translation/EncodingTypeToSerializationTypeTranslatorJUnitTest.java new file mode 100644 index 0000000..72ba4ad --- /dev/null +++ b/geode-protobuf/src/test/java/org/apache/geode/serialization/protobuf/translation/EncodingTypeToSerializationTypeTranslatorJUnitTest.java @@ -0,0 +1,65 @@ +package org.apache.geode.serialization.protobuf.translation; + +import static org.junit.Assert.assertSame; + +import org.apache.geode.protocol.protobuf.BasicTypes; +import org.apache.geode.serialization.SerializationType; +import org.apache.geode.serialization.protobuf.translation.exception.UnsupportedEncodingTypeException; +import org.apache.geode.test.junit.categories.UnitTest; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +@Category(UnitTest.class) +public class EncodingTypeToSerializationTypeTranslatorJUnitTest { + + @Test + public void testTranslateEncodingTypes() throws UnsupportedEncodingTypeException { + EncodingTypeToSerializationTypeTranslator translator = + new EncodingTypeToSerializationTypeTranslator(); + assertSame(SerializationType.INT, + translator.getSerializationTypeForEncodingType(BasicTypes.EncodingType.INT)); + assertSame(SerializationType.LONG, + translator.getSerializationTypeForEncodingType(BasicTypes.EncodingType.LONG)); + assertSame(SerializationType.SHORT, + translator.getSerializationTypeForEncodingType(BasicTypes.EncodingType.SHORT)); + assertSame(SerializationType.BYTE, + translator.getSerializationTypeForEncodingType(BasicTypes.EncodingType.BYTE)); + assertSame(SerializationType.BOOLEAN, + translator.getSerializationTypeForEncodingType(BasicTypes.EncodingType.BOOLEAN)); + assertSame(SerializationType.BYTE_BLOB, + translator.getSerializationTypeForEncodingType(BasicTypes.EncodingType.BINARY)); + assertSame(SerializationType.FLOAT, + translator.getSerializationTypeForEncodingType(BasicTypes.EncodingType.FLOAT)); + assertSame(SerializationType.DOUBLE, + translator.getSerializationTypeForEncodingType(BasicTypes.EncodingType.DOUBLE)); + assertSame(SerializationType.STRING, + translator.getSerializationTypeForEncodingType(BasicTypes.EncodingType.STRING)); + assertSame(SerializationType.JSON, + translator.getSerializationTypeForEncodingType(BasicTypes.EncodingType.JSON)); + } + + @Test(expected = UnsupportedEncodingTypeException.class) + public void testTranslateInvalidEncoding_throwsException() + throws UnsupportedEncodingTypeException { + + EncodingTypeToSerializationTypeTranslator translator = + new EncodingTypeToSerializationTypeTranslator(); + translator.getSerializationTypeForEncodingType(BasicTypes.EncodingType.INVALID); + } + + @Test + public void testAllEncodingTypeTranslations() { + EncodingTypeToSerializationTypeTranslator translator = + new EncodingTypeToSerializationTypeTranslator(); + for (BasicTypes.EncodingType encodingType : BasicTypes.EncodingType.values()) { + if (!(encodingType.equals(BasicTypes.EncodingType.UNRECOGNIZED) || encodingType + .equals(BasicTypes.EncodingType.INVALID))) { + try { + translator.getSerializationTypeForEncodingType(encodingType); + } catch (UnsupportedEncodingTypeException e) { + e.printStackTrace(); + } + } + } + } +} http://git-wip-us.apache.org/repos/asf/geode/blob/02860bab/geode-protobuf/src/test/java/org/apache/geode/serialization/registry/CodecRegistryJUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-protobuf/src/test/java/org/apache/geode/serialization/registry/CodecRegistryJUnitTest.java b/geode-protobuf/src/test/java/org/apache/geode/serialization/registry/CodecRegistryJUnitTest.java index 19d8edb..da63f31 100644 --- a/geode-protobuf/src/test/java/org/apache/geode/serialization/registry/CodecRegistryJUnitTest.java +++ b/geode-protobuf/src/test/java/org/apache/geode/serialization/registry/CodecRegistryJUnitTest.java @@ -1,35 +1,32 @@ /* - * 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 + * 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 + * 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. + * 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.geode.serialization.registry; import org.apache.geode.serialization.SerializationType; import org.apache.geode.serialization.TypeCodec; -import org.apache.geode.serialization.registry.SerializationCodecRegistry; -import org.apache.geode.serialization.registry.exception.CodecAlreadyRegisteredForType; +import org.apache.geode.serialization.registry.exception.CodecAlreadyRegisteredForTypeException; import org.apache.geode.serialization.registry.exception.CodecNotRegisteredForTypeException; +import org.apache.geode.test.junit.categories.UnitTest; import org.junit.Assert; import org.junit.Test; +import org.junit.experimental.categories.Category; -/** - * Created by ukohlmeyer on 6/13/17. - */ +@Category(UnitTest.class) public class CodecRegistryJUnitTest { @Test - public void testRegisterCodec() { + public void testRegisterCodec() throws CodecAlreadyRegisteredForTypeException { SerializationCodecRegistry codecRegistry = new SerializationCodecRegistry(); Assert.assertEquals(0, codecRegistry.getRegisteredCodecCount()); codecRegistry.register(SerializationType.INT, new DummyTypeCodec()); @@ -37,21 +34,24 @@ public class CodecRegistryJUnitTest { } @Test - public void testRegisteringCodecForRegisteredType_throwsException() { + public void testRegisteringCodecForRegisteredType_throwsException() + throws CodecAlreadyRegisteredForTypeException { SerializationCodecRegistry codecRegistry = new SerializationCodecRegistry(); codecRegistry.register(SerializationType.INT, new DummyTypeCodec()); boolean caughtException = false; try { codecRegistry.register(SerializationType.INT, new DummyTypeCodec()); - } catch (CodecAlreadyRegisteredForType e) { + } catch (CodecAlreadyRegisteredForTypeException e) { caughtException = true; } - Assert.assertTrue("This was supposed to have thrown a CodecAlreadyRegisteredException",caughtException); + Assert.assertTrue("This was supposed to have thrown a CodecAlreadyRegisteredException", + caughtException); } @Test - public void testGetRegisteredCodec() { + public void testGetRegisteredCodec() + throws CodecAlreadyRegisteredForTypeException, CodecNotRegisteredForTypeException { SerializationCodecRegistry codecRegistry = new SerializationCodecRegistry(); TypeCodec expectedCodec = new DummyTypeCodec(); codecRegistry.register(SerializationType.INT, expectedCodec); @@ -69,7 +69,8 @@ public class CodecRegistryJUnitTest { } catch (CodecNotRegisteredForTypeException e) { caughtException = true; } - Assert.assertTrue("This should have thrown a CodecNotRegisteredForTypeException", caughtException); + Assert.assertTrue("This should have thrown a CodecNotRegisteredForTypeException", + caughtException); } class DummyTypeCodec implements TypeCodec {
