@java.lang.Override public boolean equals(final java.lang.Object obj) { if (obj == this) { return true; } if (!(obj instanceof org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.PutIfAbsentResponse)) { return super.equals(obj); } org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.PutIfAbsentResponse other = (org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.PutIfAbsentResponse) obj; boolean result = true; result = result && (hasOldValue() == other.hasOldValue()); if (hasOldValue()) { result = result && getOldValue() .equals(other.getOldValue()); } result = result && unknownFields.equals(other.unknownFields); return result; }
/** * <code>.org.apache.geode.internal.protocol.protobuf.v1.PutIfAbsentResponse putIfAbsentResponse = 35;</code> */ public Builder mergePutIfAbsentResponse(org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.PutIfAbsentResponse value) { if (putIfAbsentResponseBuilder_ == null) { if (messageTypeCase_ == 35 && messageType_ != org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.PutIfAbsentResponse.getDefaultInstance()) { messageType_ = org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.PutIfAbsentResponse.newBuilder((org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.PutIfAbsentResponse) messageType_) .mergeFrom(value).buildPartial(); } else { messageType_ = value; } onChanged(); } else { if (messageTypeCase_ == 35) { putIfAbsentResponseBuilder_.mergeFrom(value); } putIfAbsentResponseBuilder_.setMessage(value); } messageTypeCase_ = 35; return this; } /**
@java.lang.Override public org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.PutIfAbsentResponse buildPartial() { org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.PutIfAbsentResponse result = new org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.PutIfAbsentResponse(this); if (oldValueBuilder_ == null) { result.oldValue_ = oldValue_; } else { result.oldValue_ = oldValueBuilder_.build(); } onBuilt(); return result; }
case 35: hash = (37 * hash) + PUTIFABSENTRESPONSE_FIELD_NUMBER; hash = (53 * hash) + getPutIfAbsentResponse().hashCode(); break; case 0:
case 35: result = result && getPutIfAbsentResponse() .equals(other.getPutIfAbsentResponse()); break; case 0:
/** * <code>.org.apache.geode.internal.protocol.protobuf.v1.PutIfAbsentResponse putIfAbsentResponse = 35;</code> */ private com.google.protobuf.SingleFieldBuilderV3< org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.PutIfAbsentResponse, org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.PutIfAbsentResponse.Builder, org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.PutIfAbsentResponseOrBuilder> getPutIfAbsentResponseFieldBuilder() { if (putIfAbsentResponseBuilder_ == null) { if (!(messageTypeCase_ == 35)) { messageType_ = org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.PutIfAbsentResponse.getDefaultInstance(); } putIfAbsentResponseBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.PutIfAbsentResponse, org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.PutIfAbsentResponse.Builder, org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.PutIfAbsentResponseOrBuilder>( (org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.PutIfAbsentResponse) messageType_, getParentForChildren(), isClean()); messageType_ = null; } messageTypeCase_ = 35; onChanged();; return putIfAbsentResponseBuilder_; } @java.lang.Override
/** * <code>.org.apache.geode.internal.protocol.protobuf.v1.PutIfAbsentResponse putIfAbsentResponse = 35;</code> */ public org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.PutIfAbsentResponse getPutIfAbsentResponse() { if (putIfAbsentResponseBuilder_ == null) { if (messageTypeCase_ == 35) { return (org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.PutIfAbsentResponse) messageType_; } return org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.PutIfAbsentResponse.getDefaultInstance(); } else { if (messageTypeCase_ == 35) { return putIfAbsentResponseBuilder_.getMessage(); } return org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.PutIfAbsentResponse.getDefaultInstance(); } } /**
@Override public Result<RegionAPI.PutIfAbsentResponse> process( ProtobufSerializationService serializationService, RegionAPI.PutIfAbsentRequest request, MessageExecutionContext messageExecutionContext) throws InvalidExecutionContextException, ConnectionStateException, EncodingException, DecodingException { final String regionName = request.getRegionName(); final BasicTypes.Entry entry = request.getEntry(); Object decodedValue = serializationService.decode(entry.getValue()); Object decodedKey = serializationService.decode(entry.getKey()); final Object oldValue = messageExecutionContext.getSecureCache().putIfAbsent(regionName, decodedKey, decodedValue); return Success.of(RegionAPI.PutIfAbsentResponse.newBuilder() .setOldValue(serializationService.encode(oldValue)).build()); } }
@java.lang.Override public int hashCode() { if (memoizedHashCode != 0) { return memoizedHashCode; } int hash = 41; hash = (19 * hash) + getDescriptor().hashCode(); if (hasOldValue()) { hash = (37 * hash) + OLDVALUE_FIELD_NUMBER; hash = (53 * hash) + getOldValue().hashCode(); } hash = (29 * hash) + unknownFields.hashCode(); memoizedHashCode = hash; return hash; }
@java.lang.Override public Builder newBuilderForType() { return newBuilder(); } public static Builder newBuilder() {
/** * <code>.org.apache.geode.internal.protocol.protobuf.v1.PutIfAbsentResponse putIfAbsentResponse = 35;</code> */ public org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.PutIfAbsentResponseOrBuilder getPutIfAbsentResponseOrBuilder() { if ((messageTypeCase_ == 35) && (putIfAbsentResponseBuilder_ != null)) { return putIfAbsentResponseBuilder_.getMessageOrBuilder(); } else { if (messageTypeCase_ == 35) { return (org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.PutIfAbsentResponse) messageType_; } return org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.PutIfAbsentResponse.getDefaultInstance(); } } /**
@java.lang.Override public org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.PutIfAbsentResponse getDefaultInstanceForType() { return org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.PutIfAbsentResponse.getDefaultInstance(); }
@java.lang.Override public int getSerializedSize() { int size = memoizedSize; if (size != -1) return size; size = 0; if (oldValue_ != null) { size += com.google.protobuf.CodedOutputStream .computeMessageSize(1, getOldValue()); } size += unknownFields.getSerializedSize(); memoizedSize = size; return size; }
@java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { if (oldValue_ != null) { output.writeMessage(1, getOldValue()); } unknownFields.writeTo(output); }
/** * <code>.org.apache.geode.internal.protocol.protobuf.v1.PutIfAbsentResponse putIfAbsentResponse = 35;</code> */ public org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.PutIfAbsentResponse getPutIfAbsentResponse() { if (messageTypeCase_ == 35) { return (org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.PutIfAbsentResponse) messageType_; } return org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.PutIfAbsentResponse.getDefaultInstance(); } /**
@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); }
@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()); }
/** * <code>.org.apache.geode.internal.protocol.protobuf.v1.EncodedValue oldValue = 1;</code> */ public org.apache.geode.internal.protocol.protobuf.v1.BasicTypes.EncodedValueOrBuilder getOldValueOrBuilder() { return getOldValue(); }
@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); }
@Test public void existingEntryFails() throws Exception { when(regionMock.putIfAbsent(TEST_KEY, TEST_VALUE)).thenReturn(1); Result<RegionAPI.PutIfAbsentResponse> result1 = operationHandler.process(serializationService, generateTestRequest(), TestExecutionContext.getNoAuthCacheExecutionContext(cacheStub)); assertNotNull(serializationService.decode(result1.getMessage().getOldValue())); verify(regionMock).putIfAbsent(TEST_KEY, TEST_VALUE); verify(regionMock, times(1)).putIfAbsent(any(), any()); }