forked from apache/geode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GEODE-4772: Enhance new protocol with ability to clear region of all …
…entries. (apache#1590) * GEODE-4772: Enhance region with ability to clear. * GEODE-4772: Address review comments. * GEODE-4772: Spotless!!!!!
- Loading branch information
1 parent
0908acb
commit 3939595
Showing
22 changed files
with
207 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
...g/apache/geode/internal/protocol/protobuf/v1/operations/ClearRequestOperationHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* 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.internal.protocol.protobuf.v1.operations; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
import org.apache.geode.annotations.Experimental; | ||
import org.apache.geode.cache.Region; | ||
import org.apache.geode.internal.exception.InvalidExecutionContextException; | ||
import org.apache.geode.internal.protocol.operations.ProtobufOperationHandler; | ||
import org.apache.geode.internal.protocol.protobuf.v1.BasicTypes; | ||
import org.apache.geode.internal.protocol.protobuf.v1.Failure; | ||
import org.apache.geode.internal.protocol.protobuf.v1.MessageExecutionContext; | ||
import org.apache.geode.internal.protocol.protobuf.v1.ProtobufSerializationService; | ||
import org.apache.geode.internal.protocol.protobuf.v1.RegionAPI; | ||
import org.apache.geode.internal.protocol.protobuf.v1.Result; | ||
import org.apache.geode.internal.protocol.protobuf.v1.Success; | ||
import org.apache.geode.internal.protocol.protobuf.v1.serialization.exception.DecodingException; | ||
import org.apache.geode.security.ResourcePermission; | ||
|
||
@Experimental | ||
public class ClearRequestOperationHandler | ||
implements ProtobufOperationHandler<RegionAPI.ClearRequest, RegionAPI.ClearResponse> { | ||
private static final Logger logger = LogManager.getLogger(); | ||
|
||
@Override | ||
public Result<RegionAPI.ClearResponse> process(ProtobufSerializationService serializationService, | ||
RegionAPI.ClearRequest request, MessageExecutionContext messageExecutionContext) | ||
throws InvalidExecutionContextException, DecodingException { | ||
|
||
String regionName = request.getRegionName(); | ||
Region region = messageExecutionContext.getCache().getRegion(regionName); | ||
if (region == null) { | ||
logger.error("Received clear request for nonexistent region: {}", regionName); | ||
return Failure.of(BasicTypes.ErrorCode.SERVER_ERROR, | ||
"Region \"" + regionName + "\" not found"); | ||
} | ||
|
||
region.clear(); | ||
|
||
return Success.of(RegionAPI.ClearResponse.newBuilder().build()); | ||
} | ||
|
||
public static ResourcePermission determineRequiredPermission(RegionAPI.ClearRequest request, | ||
ProtobufSerializationService serializer) throws DecodingException { | ||
return new ResourcePermission(ResourcePermission.Resource.DATA, | ||
ResourcePermission.Operation.WRITE, request.getRegionName()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
...geode/internal/protocol/protobuf/v1/operations/ClearRequestOperationHandlerJUnitTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* 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.internal.protocol.protobuf.v1.operations; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.experimental.categories.Category; | ||
|
||
import org.apache.geode.cache.Region; | ||
import org.apache.geode.internal.protocol.TestExecutionContext; | ||
import org.apache.geode.internal.protocol.protobuf.v1.BasicTypes; | ||
import org.apache.geode.internal.protocol.protobuf.v1.ClientProtocol; | ||
import org.apache.geode.internal.protocol.protobuf.v1.Failure; | ||
import org.apache.geode.internal.protocol.protobuf.v1.ProtobufRequestUtilities; | ||
import org.apache.geode.internal.protocol.protobuf.v1.ProtobufSerializationService; | ||
import org.apache.geode.internal.protocol.protobuf.v1.RegionAPI; | ||
import org.apache.geode.internal.protocol.protobuf.v1.Result; | ||
import org.apache.geode.internal.protocol.protobuf.v1.Success; | ||
import org.apache.geode.internal.protocol.protobuf.v1.serialization.exception.DecodingException; | ||
import org.apache.geode.internal.protocol.protobuf.v1.serialization.exception.EncodingException; | ||
import org.apache.geode.test.junit.categories.UnitTest; | ||
|
||
@Category(UnitTest.class) | ||
public class ClearRequestOperationHandlerJUnitTest extends OperationHandlerJUnitTest { | ||
private final String TEST_REGION = "test region"; | ||
private final String MISSING_REGION = "missing region"; | ||
private Region regionStub; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
regionStub = mock(Region.class); | ||
|
||
when(cacheStub.getRegion(TEST_REGION)).thenReturn(regionStub); | ||
when(cacheStub.getRegion(MISSING_REGION)).thenReturn(null); | ||
operationHandler = new ClearRequestOperationHandler(); | ||
} | ||
|
||
@Test | ||
public void processReturnsSuccessForValidRegion() throws Exception { | ||
RegionAPI.ClearRequest removeRequest = | ||
ProtobufRequestUtilities.createClearRequest(TEST_REGION).getClearRequest(); | ||
Result result = operationHandler.process(serializationService, removeRequest, | ||
TestExecutionContext.getNoAuthCacheExecutionContext(cacheStub)); | ||
|
||
assertTrue(result instanceof Success); | ||
} | ||
|
||
@Test | ||
public void processReturnsFailureForInvalidRegion() throws Exception { | ||
RegionAPI.ClearRequest removeRequest = | ||
ProtobufRequestUtilities.createClearRequest(MISSING_REGION).getClearRequest(); | ||
Result result = operationHandler.process(serializationService, removeRequest, | ||
TestExecutionContext.getNoAuthCacheExecutionContext(cacheStub)); | ||
|
||
assertTrue(result instanceof Failure); | ||
ClientProtocol.ErrorResponse errorMessage = result.getErrorMessage(); | ||
assertEquals(BasicTypes.ErrorCode.SERVER_ERROR, errorMessage.getError().getErrorCode()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.