return builder.setCustomObjectResult(customBytes).build(); builder.setNullResult(NullValue.NULL_VALUE); } else if (Integer.class.equals(unencodedValue.getClass())) { builder.setIntResult((Integer) unencodedValue); } else if (Long.class.equals(unencodedValue.getClass())) { builder.setLongResult((Long) unencodedValue); } else if (Short.class.equals(unencodedValue.getClass())) { builder.setShortResult((Short) unencodedValue); } else if (Byte.class.equals(unencodedValue.getClass())) { builder.setByteResult((Byte) unencodedValue); } else if (Double.class.equals(unencodedValue.getClass())) { builder.setDoubleResult((Double) unencodedValue); } else if (Float.class.equals(unencodedValue.getClass())) { builder.setFloatResult((Float) unencodedValue); } else if (byte[].class.equals(unencodedValue.getClass())) { builder.setBinaryResult(ByteString.copyFrom((byte[]) unencodedValue)); } else if (Boolean.class.equals(unencodedValue.getClass())) { builder.setBooleanResult((Boolean) unencodedValue); } else if (String.class.equals(unencodedValue.getClass())) { builder.setStringResult((String) unencodedValue); } else if (JSONWrapper.class.isAssignableFrom(unencodedValue.getClass())) { builder.setJsonObjectResult(((JSONWrapper) unencodedValue).getJSON()); } else { ByteString customBytes = customSerialize(unencodedValue); if (customBytes != null) { builder.setCustomObjectResult(customBytes); } else { throw new IllegalStateException("We don't know how to handle an object of type "
if (serializer.supportsPrimitives()) { ByteString encoded = serializer.serialize(value); return builder.setCustomObjectResult(encoded).build(); return builder.setNullResult(NullValue.NULL_VALUE).build(); switch (protobufEncodingTypes) { case INT: { builder.setIntResult((Integer) value); break; builder.setLongResult((Long) value); break; builder.setShortResult((Short) value); break; builder.setByteResult((Byte) value); break; builder.setDoubleResult((Double) value); break; builder.setFloatResult((Float) value); break; builder.setBinaryResult(ByteString.copyFrom((byte[]) value)); break;
switch (other.getValueCase()) { case INTRESULT: { setIntResult(other.getIntResult()); break; setLongResult(other.getLongResult()); break; setShortResult(other.getShortResult()); break; setByteResult(other.getByteResult()); break; setBooleanResult(other.getBooleanResult()); break; setDoubleResult(other.getDoubleResult()); break; setFloatResult(other.getFloatResult()); break; setBinaryResult(other.getBinaryResult()); break; valueCase_ = 9; value_ = other.value_; onChanged();
@Test public void processReturnsErrorUnableToDecodeRequest() throws Exception { Exception exception = new DecodingException("error finding codec for type"); ProtobufSerializationService serializationServiceStub = mock(ProtobufSerializationService.class); when(serializationServiceStub.decode(any())).thenReturn(TEST_KEY1, TEST_VALUE1) .thenThrow(exception); when(serializationServiceStub.encode(any())) .thenReturn(BasicTypes.EncodedValue.newBuilder().setStringResult("some string").build()); BasicTypes.EncodedValue encodedObject1 = BasicTypes.EncodedValue.newBuilder().setStringResult(TEST_KEY1).build(); BasicTypes.EncodedValue encodedObject2 = BasicTypes.EncodedValue.newBuilder().setStringResult(TEST_KEY2).build(); Set<BasicTypes.Entry> entries = new HashSet<>(); entries.add(ProtobufUtilities.createEntry(encodedObject1, encodedObject1)); entries.add(ProtobufUtilities.createEntry(encodedObject2, encodedObject2)); RegionAPI.PutAllRequest putAllRequest = ProtobufRequestUtilities.createPutAllRequest(TEST_REGION, entries).getPutAllRequest(); expectedException.expect(DecodingException.class); Result response = operationHandler.process(serializationServiceStub, putAllRequest, TestExecutionContext.getNoAuthCacheExecutionContext(cacheStub)); }
/** * <pre> * some functions don't return results. * </pre> * * <code>repeated .org.apache.geode.internal.protocol.protobuf.v1.EncodedValue results = 1;</code> */ public Builder setResults( int index, org.apache.geode.internal.protocol.protobuf.v1.BasicTypes.EncodedValue.Builder builderForValue) { if (resultsBuilder_ == null) { ensureResultsIsMutable(); results_.set(index, builderForValue.build()); onChanged(); } else { resultsBuilder_.setMessage(index, builderForValue.build()); } return this; } /**
/** * <pre> * some functions don't return results. * </pre> * * <code>repeated .org.apache.geode.internal.protocol.protobuf.v1.EncodedValue results = 1;</code> */ public Builder addResults( int index, org.apache.geode.internal.protocol.protobuf.v1.BasicTypes.EncodedValue.Builder builderForValue) { if (resultsBuilder_ == null) { ensureResultsIsMutable(); results_.add(index, builderForValue.build()); onChanged(); } else { resultsBuilder_.addMessage(index, builderForValue.build()); } return this; } /**
/** * <pre> * some functions don't return results. * </pre> * * <code>repeated .org.apache.geode.internal.protocol.protobuf.v1.EncodedValue results = 1;</code> */ public Builder addResults( org.apache.geode.internal.protocol.protobuf.v1.BasicTypes.EncodedValue.Builder builderForValue) { if (resultsBuilder_ == null) { ensureResultsIsMutable(); results_.add(builderForValue.build()); onChanged(); } else { resultsBuilder_.addMessage(builderForValue.build()); } return this; } /**
/** * <pre> * some functions don't return results. * </pre> * * <code>repeated .org.apache.geode.internal.protocol.protobuf.v1.EncodedValue results = 1;</code> */ public Builder setResults( int index, org.apache.geode.internal.protocol.protobuf.v1.BasicTypes.EncodedValue.Builder builderForValue) { if (resultsBuilder_ == null) { ensureResultsIsMutable(); results_.set(index, builderForValue.build()); onChanged(); } else { resultsBuilder_.setMessage(index, builderForValue.build()); } return this; } /**
@Test public void processReturnsErrorUnableToDecodeRequest() throws Exception { Exception exception = new DecodingException("error finding codec for type"); ProtobufSerializationService serializationServiceStub = mock(ProtobufSerializationService.class); when(serializationServiceStub.decodeList(any())).thenThrow(exception); BasicTypes.EncodedValue encodedKey1 = BasicTypes.EncodedValue.newBuilder().setStringResult(TEST_KEY1).build(); BasicTypes.EncodedValue encodedKey2 = BasicTypes.EncodedValue.newBuilder().setStringResult(TEST_KEY2).build(); Set<BasicTypes.EncodedValue> keys = new HashSet<>(); keys.add(encodedKey1); keys.add(encodedKey2); RegionAPI.GetAllRequest getRequest = ProtobufRequestUtilities.createGetAllRequest(TEST_REGION, keys); expectedException.expect(DecodingException.class); operationHandler.process(serializationServiceStub, getRequest, TestExecutionContext.getNoAuthCacheExecutionContext(cacheStub)); }
/** * <pre> * some functions don't return results. * </pre> * * <code>repeated .org.apache.geode.internal.protocol.protobuf.v1.EncodedValue results = 1;</code> */ public Builder addResults( org.apache.geode.internal.protocol.protobuf.v1.BasicTypes.EncodedValue.Builder builderForValue) { if (resultsBuilder_ == null) { ensureResultsIsMutable(); results_.add(builderForValue.build()); onChanged(); } else { resultsBuilder_.addMessage(builderForValue.build()); } return this; } /**
/** * <pre> * some functions don't return results. * </pre> * * <code>repeated .org.apache.geode.internal.protocol.protobuf.v1.EncodedValue results = 1;</code> */ public Builder setResults( int index, org.apache.geode.internal.protocol.protobuf.v1.BasicTypes.EncodedValue.Builder builderForValue) { if (resultsBuilder_ == null) { ensureResultsIsMutable(); results_.set(index, builderForValue.build()); onChanged(); } else { resultsBuilder_.setMessage(index, builderForValue.build()); } return this; } /**
/** * <pre> * some functions don't return results. * </pre> * * <code>repeated .org.apache.geode.internal.protocol.protobuf.v1.EncodedValue results = 1;</code> */ public Builder addResults( int index, org.apache.geode.internal.protocol.protobuf.v1.BasicTypes.EncodedValue.Builder builderForValue) { if (resultsBuilder_ == null) { ensureResultsIsMutable(); results_.add(index, builderForValue.build()); onChanged(); } else { resultsBuilder_.addMessage(index, builderForValue.build()); } return this; } /**
/** * <pre> * some functions don't return results. * </pre> * * <code>repeated .org.apache.geode.internal.protocol.protobuf.v1.EncodedValue results = 1;</code> */ public Builder addResults( int index, org.apache.geode.internal.protocol.protobuf.v1.BasicTypes.EncodedValue.Builder builderForValue) { if (resultsBuilder_ == null) { ensureResultsIsMutable(); results_.add(index, builderForValue.build()); onChanged(); } else { resultsBuilder_.addMessage(index, builderForValue.build()); } return this; } /**
/** * <pre> * some functions don't return results. * </pre> * * <code>repeated .org.apache.geode.internal.protocol.protobuf.v1.EncodedValue results = 1;</code> */ public Builder addResults( org.apache.geode.internal.protocol.protobuf.v1.BasicTypes.EncodedValue.Builder builderForValue) { if (resultsBuilder_ == null) { ensureResultsIsMutable(); results_.add(builderForValue.build()); onChanged(); } else { resultsBuilder_.addMessage(builderForValue.build()); } return this; } /**
@Test(expected = DecodingException.class) public void processThrowsExceptionWhenUnableToDecode() throws Exception { String exceptionText = "unsupported type!"; Exception exception = new DecodingException(exceptionText); ProtobufSerializationService serializationServiceStub = mock(ProtobufSerializationService.class); when(serializationServiceStub.decode(any())).thenThrow(exception); BasicTypes.EncodedValue encodedKey = BasicTypes.EncodedValue.newBuilder() .setJsonObjectResult("{\"someKey\":\"someValue\"}").build(); PutRequestOperationHandler operationHandler = new PutRequestOperationHandler(); BasicTypes.EncodedValue testValue = serializationService.encode(TEST_VALUE); BasicTypes.Entry testEntry = ProtobufUtilities.createEntry(encodedKey, testValue); RegionAPI.PutRequest putRequest = ProtobufRequestUtilities.createPutRequest(TEST_REGION, testEntry).getPutRequest(); operationHandler.process(serializationServiceStub, putRequest, TestExecutionContext.getNoAuthCacheExecutionContext(cacheStub)); }
/** * <code>.org.apache.geode.internal.protocol.protobuf.v1.EncodedValue singleResult = 1;</code> */ public Builder setSingleResult( org.apache.geode.internal.protocol.protobuf.v1.BasicTypes.EncodedValue.Builder builderForValue) { if (singleResultBuilder_ == null) { result_ = builderForValue.build(); onChanged(); } else { singleResultBuilder_.setMessage(builderForValue.build()); } resultCase_ = 1; return this; } /**
/** * <code>repeated .org.apache.geode.internal.protocol.protobuf.v1.EncodedValue bindParameter = 2;</code> */ public Builder addBindParameter( int index, org.apache.geode.internal.protocol.protobuf.v1.BasicTypes.EncodedValue.Builder builderForValue) { if (bindParameterBuilder_ == null) { ensureBindParameterIsMutable(); bindParameter_.add(index, builderForValue.build()); onChanged(); } else { bindParameterBuilder_.addMessage(index, builderForValue.build()); } return this; } /**
/** * <code>repeated .org.apache.geode.internal.protocol.protobuf.v1.EncodedValue bindParameter = 2;</code> */ public Builder addBindParameter( org.apache.geode.internal.protocol.protobuf.v1.BasicTypes.EncodedValue.Builder builderForValue) { if (bindParameterBuilder_ == null) { ensureBindParameterIsMutable(); bindParameter_.add(builderForValue.build()); onChanged(); } else { bindParameterBuilder_.addMessage(builderForValue.build()); } return this; } /**
/** * <code>repeated .org.apache.geode.internal.protocol.protobuf.v1.EncodedValue key = 2;</code> */ public Builder addKey( org.apache.geode.internal.protocol.protobuf.v1.BasicTypes.EncodedValue.Builder builderForValue) { if (keyBuilder_ == null) { ensureKeyIsMutable(); key_.add(builderForValue.build()); onChanged(); } else { keyBuilder_.addMessage(builderForValue.build()); } return this; } /**
/** * <code>repeated .org.apache.geode.internal.protocol.protobuf.v1.EncodedValue keyFilter = 4;</code> */ public Builder addKeyFilter( int index, org.apache.geode.internal.protocol.protobuf.v1.BasicTypes.EncodedValue.Builder builderForValue) { if (keyFilterBuilder_ == null) { ensureKeyFilterIsMutable(); keyFilter_.add(index, builderForValue.build()); onChanged(); } else { keyFilterBuilder_.addMessage(index, builderForValue.build()); } return this; } /**