Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions cppcache/integration/test/RegisterKeysTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@

#include <gmock/gmock.h>

#include <condition_variable>
#include <mutex>

#include <boost/thread/latch.hpp>

#include <gtest/gtest.h>
Expand All @@ -33,6 +30,7 @@
#include "framework/Cluster.h"
#include "framework/Framework.h"
#include "framework/Gfsh.h"
#include "gmock_actions.hpp"
#include "mock/CacheListenerMock.hpp"
#include "util/concurrent/binary_semaphore.hpp"

Expand All @@ -54,10 +52,6 @@ using ::testing::DoAll;
using ::testing::InvokeWithoutArgs;
using ::testing::Return;

ACTION_P(ReleaseSem, sem) { sem->release(); }
ACTION_P(AcquireSem, sem) { sem->acquire(); }
ACTION_P(CountDownLatch, latch) { latch->count_down(); }

Cache createTestCache() {
CacheFactory cacheFactory;
return cacheFactory.set("log-level", "none")
Expand Down
41 changes: 23 additions & 18 deletions cppcache/integration/test/ServerDisconnectWithListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,36 @@
* limitations under the License.
*/

#include <gtest/gtest.h>
#include <util/concurrent/binary_semaphore.hpp>

#include <geode/Cache.hpp>
#include <geode/CacheFactory.hpp>
#include <geode/CacheListener.hpp>
#include <geode/EntryEvent.hpp>
#include <geode/PoolManager.hpp>
#include <geode/RegionEvent.hpp>
#include <geode/RegionFactory.hpp>
#include <geode/RegionShortcut.hpp>

#include "framework/Cluster.h"
#include "framework/Framework.h"
#include "framework/Gfsh.h"
#include "gmock_actions.hpp"
#include "mock/CacheListenerMock.hpp"

namespace {

using apache::geode::client::binary_semaphore;
using apache::geode::client::Cache;
using apache::geode::client::CacheableInt16;
using apache::geode::client::CacheFactory;
using apache::geode::client::CacheListener;
using apache::geode::client::CacheListenerMock;
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; }
};
using ::testing::_;
using ::testing::NiceMock;

Cache createTestCache() {
CacheFactory cacheFactory;
Expand Down Expand Up @@ -72,22 +74,25 @@ TEST(ServerDisconnect, WithRegionDisconnectedListener) {
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");
binary_semaphore live_sem{0};
binary_semaphore shut_sem{1};
auto listener = std::make_shared<NiceMock<CacheListenerMock>>();
EXPECT_CALL(*listener, afterRegionLive(_))
.WillRepeatedly(AcquireSem(&shut_sem));
EXPECT_CALL(*listener, afterRegionDisconnected(_))
.WillRepeatedly(ReleaseSem(&shut_sem));
auto region =
regionFactory.setPoolName("pool").setCacheListener(listener).create(
"region");

region->put("one", std::make_shared<CacheableInt16>(1));

auto& servers = cluster.getServers();
servers[0].stop();
shut_sem.acquire();
shut_sem.release();

try {
region->put("two", std::make_shared<CacheableInt16>(2));
} catch (const NotConnectedException&) {
}

ASSERT_EQ(isDisconnected, true);
EXPECT_THROW(region->put("two", std::make_shared<CacheableInt16>(2)),
NotConnectedException);
}
} // namespace
29 changes: 29 additions & 0 deletions cppcache/integration/test/gmock_actions.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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.
*/

#pragma once

#ifndef GMOCK_ACTIONS_H_
#define GMOCK_ACTIONS_H_

#include <gmock/gmock.h>

ACTION_P(ReleaseSem, sem) { sem->release(); }
ACTION_P(AcquireSem, sem) { sem->acquire(); }
ACTION_P(CountDownLatch, latch) { latch->count_down(); }

#endif // GMOCK_ACTIONS_H_