[ 
https://issues.apache.org/jira/browse/GEODE-8614?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17230861#comment-17230861
 ] 

ASF GitHub Bot commented on GEODE-8614:
---------------------------------------

pivotal-jbarrett commented on a change in pull request #688:
URL: https://github.com/apache/geode-native/pull/688#discussion_r522343443



##########
File path: cppcache/integration/test/ExceptionTranslationTest.cpp
##########
@@ -0,0 +1,125 @@
+/*
+ * 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.
+ */
+
+#include <random>
+
+#include <gtest/gtest.h>
+
+#include <geode/QueryService.hpp>
+#include <geode/RegionFactory.hpp>
+#include <geode/RegionShortcut.hpp>
+
+#include "framework/Cluster.h"
+
+using apache::geode::client::Cache;
+using apache::geode::client::CacheableKey;
+using apache::geode::client::CacheableString;
+using apache::geode::client::LowMemoryException;
+using apache::geode::client::Pool;
+using apache::geode::client::QueryExecutionLowMemoryException;
+using apache::geode::client::Region;
+using apache::geode::client::RegionShortcut;
+
+using std::chrono::minutes;
+
+namespace {
+Cache createCache() {
+  using apache::geode::client::CacheFactory;
+
+  auto cache = CacheFactory()
+                   .set("log-level", "none")
+                   .set("statistic-sampling-enabled", "false")
+                   .create();
+
+  return cache;
+}
+
+std::shared_ptr<Pool> createPool(Cluster& cluster, Cache& cache) {
+  auto poolFactory = cache.getPoolManager().createFactory();
+  cluster.applyLocators(poolFactory);
+  return poolFactory.create("default");
+}
+
+std::shared_ptr<Region> setupRegion(Cache& cache,
+                                    const std::shared_ptr<Pool>& pool) {
+  auto region = cache.createRegionFactory(RegionShortcut::PROXY)
+                    .setPoolName(pool->getName())
+                    .create("region");
+
+  return region;
+}
+
+void createEntries(const std::shared_ptr<Region>& region, std::size_t count,
+                   std::size_t size) {
+  std::mt19937 generator{std::random_device{}()};
+  std::string base{"ABCDEFGHIJKLMNOPQRSTUVWXYZ"};
+
+  while (base.length() < size) {
+    base += base;
+  }
+  base = base.substr(0, size);
+
+  for (std::size_t i = 0U; i < count;) {
+    std::string value_str{base};
+    std::shuffle(value_str.begin(), value_str.end(), generator);
+
+    auto key = CacheableKey::create(std::to_string(i++));
+    auto value = CacheableString::create(value_str);
+    region->put(key, value);
+  }
+}
+}  // namespace
+
+TEST(ExceptionTranslationTest, testLowMemoryException) {
+  const auto ENTRY_SIZE = 1024U;
+  const auto ENTRIES = 1U << 20U;
+
+  Cluster cluster{LocatorCount{1}, ServerCount{1},
+                  CacheXMLFiles{std::vector<std::string>{

Review comment:
       Outside the scope of this fix but interesting thought. I wonder if this 
could take an initializer list to magically construct the 
`std::vector<std::string>` for readability. 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Provide an specific client-side exception for server LowMemoryException
> -----------------------------------------------------------------------
>
>                 Key: GEODE-8614
>                 URL: https://issues.apache.org/jira/browse/GEODE-8614
>             Project: Geode
>          Issue Type: Improvement
>          Components: native client
>    Affects Versions: 1.11.0, 1.12.0, 1.13.0
>            Reporter: Mario Salazar de Torres
>            Priority: Major
>              Labels: pull-request-available
>
> *AS AN* native client contributor
>  *I WANT* to have a client-side exception for LowMemoryException
>  *SO THAT* I can nofity accordingly from the client-side upon server 
> memory-depletion.
> —
> *Additional information*
>  This is the callstack of the LowMemoryException:
> {noformat}
> [error 2020/10/13 09:54:14.401405 UTC 140522117220352] Region::put: An 
> exception (org.apache.geode.cache.LowMemoryException: PartitionedRegion: 
> /part_a cannot process operation on key foo|0 because members 
> [192.168.240.14(dms-server-1:1)<v2>:41000] are running low on memory
> at 
> org.apache.geode.internal.cache.partitioned.RegionAdvisor.checkIfBucketSick(RegionAdvisor.java:482)
> at 
> org.apache.geode.internal.cache.PartitionedRegion.checkIfAboveThreshold(PartitionedRegion.java:2278)
> at 
> org.apache.geode.internal.cache.PartitionedRegion.putInBucket(PartitionedRegion.java:2982)
> at 
> org.apache.geode.internal.cache.PartitionedRegion.virtualPut(PartitionedRegion.java:2212)
> at 
> org.apache.geode.internal.cache.LocalRegionDataView.putEntry(LocalRegionDataView.java:170)
> at 
> org.apache.geode.internal.cache.LocalRegion.basicUpdate(LocalRegion.java:5573)
> at 
> org.apache.geode.internal.cache.LocalRegion.basicUpdate(LocalRegion.java:5533)
> at 
> org.apache.geode.internal.cache.LocalRegion.basicBridgePut(LocalRegion.java:5212)
> at 
> org.apache.geode.internal.cache.tier.sockets.command.Put65.cmdExecute(Put65.java:411)
> at 
> org.apache.geode.internal.cache.tier.sockets.BaseCommand.execute(BaseCommand.java:183)
> at 
> org.apache.geode.internal.cache.tier.sockets.ServerConnection.doNormalMessage(ServerConnection.java:848)
> at 
> org.apache.geode.internal.cache.tier.sockets.OriginalServerConnection.doOneMessage(OriginalServerConnection.java:72)
> at 
> org.apache.geode.internal.cache.tier.sockets.ServerConnection.run(ServerConnection.java:1212)
> at 
> java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
> at 
> java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
> at 
> org.apache.geode.internal.cache.tier.sockets.AcceptorImpl.lambda$initializeServerConnectionThreadPool$3(AcceptorImpl.java:676)
> at 
> org.apache.geode.logging.internal.executors.LoggingThreadFactory.lambda$newThread$0(LoggingThreadFactory.java:119)
> at java.base/java.lang.Thread.run(Thread.java:834) ) happened at remote 
> server.
> {noformat}
> Idea would be to modify *ThinClientRegion::handleServerException* in order to 
> return a new error and later on, map it to a new created exception
> *Suggestions*
>  The new exception could be called:
>  * CacheServerLowMemoryException
>  * ...



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to