You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by ji...@apache.org on 2016/07/08 15:51:44 UTC
[24/50] [abbrv] incubator-geode git commit: Added Size test and
refactored Size
Added Size test and refactored Size
Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/bad0a92d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/bad0a92d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/bad0a92d
Branch: refs/heads/develop
Commit: bad0a92d3868a39d9e1d2f01eff0c59f13c736c3
Parents: b782b6b
Author: Kevin J. Duling <kd...@pivotal.io>
Authored: Wed Jun 29 11:04:33 2016 -0700
Committer: Kevin J. Duling <kd...@pivotal.io>
Committed: Wed Jun 29 11:04:33 2016 -0700
----------------------------------------------------------------------
.../cache/tier/sockets/command/Size.java | 141 ++++++++-----------
...IntegratedClientSizeAuthDistributedTest.java | 57 ++++++++
2 files changed, 115 insertions(+), 83 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bad0a92d/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/tier/sockets/command/Size.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/tier/sockets/command/Size.java b/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/tier/sockets/command/Size.java
index 64aee67..8b11d3d 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/tier/sockets/command/Size.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/tier/sockets/command/Size.java
@@ -15,20 +15,15 @@
* limitations under the License.
*/
/**
- *
+ *
*/
package com.gemstone.gemfire.internal.cache.tier.sockets.command;
import java.io.IOException;
-import java.nio.ByteBuffer;
-import com.gemstone.gemfire.cache.EntryNotFoundException;
import com.gemstone.gemfire.cache.RegionDestroyedException;
import com.gemstone.gemfire.distributed.internal.DistributionStats;
-import com.gemstone.gemfire.i18n.LogWriterI18n;
-import com.gemstone.gemfire.internal.cache.EventID;
import com.gemstone.gemfire.internal.cache.LocalRegion;
-import com.gemstone.gemfire.internal.cache.PartitionedRegion;
import com.gemstone.gemfire.internal.cache.tier.CachedRegionHelper;
import com.gemstone.gemfire.internal.cache.tier.Command;
import com.gemstone.gemfire.internal.cache.tier.MessageType;
@@ -39,6 +34,7 @@ import com.gemstone.gemfire.internal.cache.tier.sockets.Part;
import com.gemstone.gemfire.internal.cache.tier.sockets.ServerConnection;
import com.gemstone.gemfire.internal.i18n.LocalizedStrings;
import com.gemstone.gemfire.internal.logging.log4j.LocalizedMessage;
+import com.gemstone.gemfire.internal.security.GeodeSecurityUtil;
import com.gemstone.gemfire.security.GemFireSecurityException;
@@ -46,56 +42,60 @@ public class Size extends BaseCommand {
private final static Size singleton = new Size();
+ private Size() {
+ }
+
public static Command getCommand() {
return singleton;
}
- private Size() {
+ private static void writeSizeResponse(Integer sizeCount, Message origMsg, ServerConnection servConn)
+ throws IOException {
+ Message responseMsg = servConn.getResponseMessage();
+ responseMsg.setMessageType(MessageType.RESPONSE);
+ responseMsg.setNumberOfParts(1);
+ responseMsg.setTransactionId(origMsg.getTransactionId());
+ responseMsg.addObjPart(sizeCount);
+ responseMsg.send(servConn);
}
@Override
- public void cmdExecute(Message msg, ServerConnection servConn, long start)
- throws IOException, InterruptedException {
- Part regionNamePart = null, keyPart = null, callbackArgPart = null;
- String regionName = null;
- Part eventPart = null;
- StringBuffer errMessage = new StringBuffer();
+ public void cmdExecute(Message msg, ServerConnection servConn, long start) throws IOException, InterruptedException {
+ StringBuilder errMessage = new StringBuilder();
CachedRegionHelper crHelper = servConn.getCachedRegionHelper();
CacheServerStats stats = servConn.getCacheServerStats();
servConn.setAsTrue(REQUIRES_RESPONSE);
- {
- long oldStart = start;
- start = DistributionStats.getStatTime();
- stats.incReadSizeRequestTime(start - oldStart);
- }
+ long oldStart = start;
+ start = DistributionStats.getStatTime();
+ stats.incReadSizeRequestTime(start - oldStart);
// Retrieve the data from the message parts
- regionNamePart = msg.getPart(0);
- regionName = regionNamePart.getString();
-
+ Part regionNamePart = msg.getPart(0);
+ String regionName = regionNamePart.getString();
+
if (regionName == null) {
logger.warn(LocalizedMessage.create(LocalizedStrings.BaseCommand__THE_INPUT_REGION_NAME_FOR_THE_0_REQUEST_IS_NULL, "size"));
- errMessage
- .append(LocalizedStrings.BaseCommand__THE_INPUT_REGION_NAME_FOR_THE_0_REQUEST_IS_NULL.toLocalizedString("size"));
- writeErrorResponse(msg, MessageType.SIZE_ERROR, errMessage
- .toString(), servConn);
+ errMessage.append(LocalizedStrings.BaseCommand__THE_INPUT_REGION_NAME_FOR_THE_0_REQUEST_IS_NULL.toLocalizedString("size"));
+ writeErrorResponse(msg, MessageType.SIZE_ERROR, errMessage.toString(), servConn);
servConn.setAsTrue(RESPONDED);
+ return;
+ }
+
+ LocalRegion region = (LocalRegion) crHelper.getRegion(regionName);
+ if (region == null) {
+ String reason = LocalizedStrings.BaseCommand__0_WAS_NOT_FOUND_DURING_1_REQUEST.toLocalizedString(regionName, "size");
+ writeRegionDestroyedEx(msg, regionName, reason, servConn);
+ servConn.setAsTrue(RESPONDED);
+ return;
}
- else {
- LocalRegion region = (LocalRegion)crHelper.getRegion(regionName);
- if (region == null) {
- String reason = LocalizedStrings.BaseCommand__0_WAS_NOT_FOUND_DURING_1_REQUEST.toLocalizedString(regionName,"size");
- writeRegionDestroyedEx(msg, regionName, reason, servConn);
- servConn.setAsTrue(RESPONDED);
- }
- else {
- // Size the entry
- try {
+ GeodeSecurityUtil.authorizeRegionRead(regionName);
+ // Size the entry
+ try {
/*
- *
+ *
* txtodo: doesn't seem like there is any notion of authzSize
- *
+ *
AuthorizeRequest authzRequest = servConn.getAuthzRequest();
if (authzRequest != null) {
// TODO SW: This is to handle DynamicRegionFactory destroy
@@ -113,55 +113,30 @@ public class Size extends BaseCommand {
}
}
*/
- writeSizeResponse(region.size(), msg, servConn);
- servConn.setAsTrue(RESPONDED);
- return;
- }
- catch (RegionDestroyedException rde) {
- writeException(msg, rde, false, servConn);
- servConn.setAsTrue(RESPONDED);
- return;
- }
- catch (Exception e) {
- // If an interrupted exception is thrown , rethrow it
- checkForInterrupt(servConn, e);
+ writeSizeResponse(region.size(), msg, servConn);
+ } catch (RegionDestroyedException rde) {
+ writeException(msg, rde, false, servConn);
+ } catch (Exception e) {
+ // If an interrupted exception is thrown , rethrow it
+ checkForInterrupt(servConn, e);
- // If an exception occurs during the destroy, preserve the connection
- writeException(msg, e, false, servConn);
- servConn.setAsTrue(RESPONDED);
- if (e instanceof GemFireSecurityException) {
- // Fine logging for security exceptions since these are already
- // logged by the security logger
- if (logger.isDebugEnabled())
- logger.debug("{}: Unexpected Security exception", servConn.getName(), e);
- }
- else {
- logger.warn(LocalizedMessage.create(LocalizedStrings.BaseCommand_0_UNEXPECTED_EXCEPTION, servConn.getName()), e);
- }
- servConn.setAsTrue(RESPONDED);
- return;
- } finally {
- if (logger.isDebugEnabled()) {
- logger.debug("{}: Sent size response for region {}", servConn.getName(), regionName);
- }
- stats.incWriteSizeResponseTime(DistributionStats.getStatTime()
- - start);
+ // If an exception occurs during the destroy, preserve the connection
+ writeException(msg, e, false, servConn);
+ if (e instanceof GemFireSecurityException) {
+ // Fine logging for security exceptions since these are already
+ // logged by the security logger
+ if (logger.isDebugEnabled()) {
+ logger.debug("{}: Unexpected Security exception", servConn.getName(), e);
}
+ } else {
+ logger.warn(LocalizedMessage.create(LocalizedStrings.BaseCommand_0_UNEXPECTED_EXCEPTION, servConn.getName()), e);
+ }
+ } finally {
+ if (logger.isDebugEnabled()) {
+ logger.debug("{}: Sent size response for region {}", servConn.getName(), regionName);
}
+ servConn.setAsTrue(RESPONDED);
+ stats.incWriteSizeResponseTime(DistributionStats.getStatTime() - start);
}
-
-
-
}
-
- private static void writeSizeResponse(Integer sizeCount, Message origMsg,
- ServerConnection servConn) throws IOException {
- Message responseMsg = servConn.getResponseMessage();
- responseMsg.setMessageType(MessageType.RESPONSE);
- responseMsg.setNumberOfParts(1);
- responseMsg.setTransactionId(origMsg.getTransactionId());
- responseMsg.addObjPart(sizeCount);
- responseMsg.send(servConn);
- }
-
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bad0a92d/geode-core/src/test/java/com/gemstone/gemfire/security/IntegratedClientSizeAuthDistributedTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/security/IntegratedClientSizeAuthDistributedTest.java b/geode-core/src/test/java/com/gemstone/gemfire/security/IntegratedClientSizeAuthDistributedTest.java
new file mode 100644
index 0000000..96ea297
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/security/IntegratedClientSizeAuthDistributedTest.java
@@ -0,0 +1,57 @@
+/*
+ * 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 com.gemstone.gemfire.security;
+
+
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import com.gemstone.gemfire.cache.client.ClientCache;
+import com.gemstone.gemfire.cache.client.ClientCacheFactory;
+import com.gemstone.gemfire.cache.client.internal.InternalPool;
+import com.gemstone.gemfire.cache.client.internal.SizeOp;
+import com.gemstone.gemfire.test.dunit.AsyncInvocation;
+import com.gemstone.gemfire.test.junit.categories.DistributedTest;
+
+@Category(DistributedTest.class)
+public class IntegratedClientSizeAuthDistributedTest extends AbstractIntegratedClientAuthDistributedTest {
+
+ @Test
+ public void testSize() throws InterruptedException {
+
+ AsyncInvocation ai1 = client1.invokeAsync(() -> {
+ ClientCache cache = new ClientCacheFactory(createClientProperties("stranger", "1234567")).setPoolSubscriptionEnabled(true)
+ .addPoolServer("localhost", serverPort)
+ .create();
+
+ assertNotAuthorized(() -> SizeOp.execute((InternalPool) cache.getDefaultPool(), REGION_NAME), "DATA:READ:AuthRegion");
+ });
+
+ AsyncInvocation ai2 = client2.invokeAsync(() -> {
+ ClientCache cache = new ClientCacheFactory(createClientProperties("authRegionReader", "1234567")).setPoolSubscriptionEnabled(true)
+ .addPoolServer("localhost", serverPort)
+ .create();
+
+ SizeOp.execute((InternalPool) cache.getDefaultPool(), REGION_NAME);
+ });
+
+ ai1.join();
+ ai2.join();
+ ai1.checkException();
+ ai2.checkException();
+ }
+}