/** * <code>.org.apache.geode.internal.protocol.protobuf.v1.PutIfAbsentRequest putIfAbsentRequest = 34;</code> */ public Builder mergePutIfAbsentRequest(org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.PutIfAbsentRequest value) { if (putIfAbsentRequestBuilder_ == null) { if (messageTypeCase_ == 34 && messageType_ != org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.PutIfAbsentRequest.getDefaultInstance()) { messageType_ = org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.PutIfAbsentRequest.newBuilder((org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.PutIfAbsentRequest) messageType_) .mergeFrom(value).buildPartial(); } else { messageType_ = value; } onChanged(); } else { if (messageTypeCase_ == 34) { putIfAbsentRequestBuilder_.mergeFrom(value); } putIfAbsentRequestBuilder_.setMessage(value); } messageTypeCase_ = 34; return this; } /**
@Test public void nullKeyPassedThrough() throws Exception { final RegionAPI.PutIfAbsentRequest request = RegionAPI.PutIfAbsentRequest.newBuilder() .setRegionName(TEST_REGION) .setEntry(ProtobufUtilities.createEntry(serializationService, null, TEST_VALUE)).build(); Result<RegionAPI.PutIfAbsentResponse> response = operationHandler.process(serializationService, request, TestExecutionContext.getNoAuthCacheExecutionContext(cacheStub)); assertNull(serializationService.decode(response.getMessage().getOldValue())); verify(regionMock).putIfAbsent(null, TEST_VALUE); }
@Test public void nullValuePassedThrough() throws Exception { final RegionAPI.PutIfAbsentRequest request = RegionAPI.PutIfAbsentRequest.newBuilder().setRegionName(TEST_REGION) .setEntry(ProtobufUtilities.createEntry(serializationService, TEST_KEY, null)).build(); Result<RegionAPI.PutIfAbsentResponse> response = operationHandler.process(serializationService, request, TestExecutionContext.getNoAuthCacheExecutionContext(cacheStub)); assertNull(serializationService.decode(response.getMessage().getOldValue())); verify(regionMock).putIfAbsent(TEST_KEY, null); }
@java.lang.Override public Builder newBuilderForType() { return newBuilder(); } public static Builder newBuilder() {
private RegionAPI.PutIfAbsentRequest generateTestRequest(boolean includeRegion, boolean includeEntry) throws EncodingException { RegionAPI.PutIfAbsentRequest.Builder builder = RegionAPI.PutIfAbsentRequest.newBuilder(); if (includeRegion) { builder.setRegionName(TEST_REGION); } if (includeEntry) { BasicTypes.EncodedValue testKey = serializationService.encode(TEST_KEY); BasicTypes.EncodedValue testValue = serializationService.encode(TEST_VALUE); BasicTypes.Entry testEntry = ProtobufUtilities.createEntry(testKey, testValue); builder.setEntry(testEntry); } return builder.build(); }
/** * Creates a request object containing a RegionAPI.PutIfAbsentRequest * * @param region - Name of the region to put data in * @param entry - Encoded key,value pair, see createEntry in {@link ProtobufRequestUtilities} * @return Request object containing the passed params. */ public static ClientProtocol.Message createPutIfAbsentRequest(String region, BasicTypes.Entry entry) { RegionAPI.PutIfAbsentRequest putIfAbsentRequest = RegionAPI.PutIfAbsentRequest.newBuilder().setRegionName(region).setEntry(entry).build(); return ClientProtocol.Message.newBuilder().setPutIfAbsentRequest(putIfAbsentRequest).build(); }
@Override public V putIfAbsent(K key, V value) throws IOException { final RegionAPI.PutIfAbsentRequest.Builder putIfAbsentRequest = RegionAPI.PutIfAbsentRequest .newBuilder().setRegionName(name).setEntry(valueEncoder.encodeEntry(key, value)); final Message request = Message.newBuilder().setPutIfAbsentRequest(putIfAbsentRequest).build(); final RegionAPI.PutIfAbsentResponse putIfAbsentResponse = protobufChannel .sendRequest(request, MessageTypeCase.PUTIFABSENTRESPONSE).getPutIfAbsentResponse(); return (V) valueEncoder.decodeValue(putIfAbsentResponse.getOldValue()); }