You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by mm...@apache.org on 2020/06/03 21:38:52 UTC

[geode-native] branch develop updated: GEODE-8214: Add new ServerDisconnect test (#610)

This is an automated email from the ASF dual-hosted git repository.

mmartell pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode-native.git


The following commit(s) were added to refs/heads/develop by this push:
     new 1400f50  GEODE-8214: Add new ServerDisconnect test (#610)
1400f50 is described below

commit 1400f50e97d12907fea3f5d3859cdf50ddfbc56f
Author: Michael Martell <mm...@pivotal.io>
AuthorDate: Wed Jun 3 14:38:44 2020 -0700

    GEODE-8214: Add new ServerDisconnect test (#610)
---
 cppcache/integration/test/CMakeLists.txt           |  1 +
 .../test/ServerDisconnectWithListener.cpp          | 94 ++++++++++++++++++++++
 2 files changed, 95 insertions(+)

diff --git a/cppcache/integration/test/CMakeLists.txt b/cppcache/integration/test/CMakeLists.txt
index 01a67bd..a7554fd 100644
--- a/cppcache/integration/test/CMakeLists.txt
+++ b/cppcache/integration/test/CMakeLists.txt
@@ -34,6 +34,7 @@ add_executable(cpp-integration-test
   RegionPutAllTest.cpp
   RegionPutGetAllTest.cpp
   RegisterKeysTest.cpp
+  ServerDisconnectWithListener.cpp
   SimpleAuthInitialize.cpp
   SimpleAuthInitialize.hpp
   SimpleCqListener.cpp
diff --git a/cppcache/integration/test/ServerDisconnectWithListener.cpp b/cppcache/integration/test/ServerDisconnectWithListener.cpp
new file mode 100644
index 0000000..0b6c11b
--- /dev/null
+++ b/cppcache/integration/test/ServerDisconnectWithListener.cpp
@@ -0,0 +1,94 @@
+/* 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 <gtest/gtest.h>
+
+#include <geode/Cache.hpp>
+#include <geode/CacheFactory.hpp>
+#include <geode/CacheListener.hpp>
+#include <geode/PoolManager.hpp>
+#include <geode/RegionFactory.hpp>
+#include <geode/RegionShortcut.hpp>
+
+#include "framework/Cluster.h"
+#include "framework/Framework.h"
+#include "framework/Gfsh.h"
+
+namespace {
+
+using apache::geode::client::Cache;
+using apache::geode::client::CacheableInt16;
+using apache::geode::client::CacheFactory;
+using apache::geode::client::CacheListener;
+using apache::geode::client::NotConnectedException;
+using apache::geode::client::Region;
+using apache::geode::client::RegionShortcut;
+
+static bool isDisconnected = false;
+
+class RegionDisconnectedListener : public CacheListener {
+  void afterRegionDisconnected(Region&) override { isDisconnected = true; }
+};
+
+Cache createTestCache() {
+  CacheFactory cacheFactory;
+  return cacheFactory.set("log-level", "none")
+      .set("statistic-sampling-enabled", "false")
+      .create();
+}
+
+TEST(ServerDisconnect, WithRegionDisconnectedListener) {
+  Cluster cluster{LocatorCount{1}, ServerCount{1}};
+
+  cluster.start();
+
+  cluster.getGfsh()
+      .create()
+      .region()
+      .withName("region")
+      .withType("PARTITION")
+      .execute();
+
+  auto cache = createTestCache();
+
+  auto poolFactory =
+      cache.getPoolManager().createFactory().setSubscriptionEnabled(true);
+
+  cluster.applyLocators(poolFactory);
+
+  auto pool = poolFactory.create("pool");
+  auto regionFactory =
+      cache.createRegionFactory(RegionShortcut::CACHING_PROXY);
+
+  auto regionDisconnectedListener =
+      std::make_shared<RegionDisconnectedListener>();
+  auto region = regionFactory.setPoolName("pool")
+                    .setCacheListener(regionDisconnectedListener)
+                    .create("region");
+
+  region->put("one", std::make_shared<CacheableInt16>(1));
+
+  auto& servers = cluster.getServers();
+  servers[0].stop();
+
+  try {
+    region->put("two", std::make_shared<CacheableInt16>(2));
+  } catch (const NotConnectedException&) {
+  }
+
+  ASSERT_EQ(isDisconnected, true);
+}
+}  // namespace