Skip to content

Commit e038900

Browse files
committed
Bug 37315344 - [37264961->14.1.2.0.1] CQC constructor with fCacheValues of false should configure lite mapListener (main.cpp->cpp-v14.1.2.0)
Verified with shelf build on Coh_CPP-14.1.2.0-Linux-aarch64, #2 (Dec 5, 2024, 12:38:53 PM) Changelist: 112518, Shelf: 112721 [git-p4: depot-paths = "//dev/release.cpp/coherence-cpp-v14.1.2.0/": change = 112740]
1 parent e0b29f9 commit e038900

File tree

6 files changed

+150
-11
lines changed

6 files changed

+150
-11
lines changed

include/public/coherence/net/cache/ContinuousQueryCache.hpp

+18-3
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,18 @@ class COH_EXPORT ContinuousQueryCache
7272
* @param vFilter the Filter that defines the view
7373
* @param fCacheValues pass true to cache both the keys and values of
7474
* the materialized view locally, or false to
75-
* only cache the keys
75+
* only cache the keys. Override of false described
76+
* in isCacheValues()
7677
* @param hListener an initial MapListener that will receive all
7778
* the events from the ContinuousQueryCache,
7879
* including those corresponding to its initial
7980
* population
8081
* @param vTransformer the transformer that should be used to convert
8182
* values from the underlying cache before storing
8283
* them locally
84+
* Note: When parameter fCacheValues is false, it is inferred that provided parameter
85+
* listener is a lite listener as described by fLite parameter of
86+
* addMapListener(MapListener, Filter, boolean).
8387
*/
8488
ContinuousQueryCache(NamedCache::Handle hCache,
8589
Filter::View vFilter, bool fCacheValues = false,
@@ -101,14 +105,18 @@ class COH_EXPORT ContinuousQueryCache
101105
* @param vFilter the Filter that defines the view
102106
* @param fCacheValues pass true to cache both the keys and values of
103107
* the materialized view locally, or false to
104-
* only cache the keys
108+
* only cache the keys. Override of false described
109+
* in isCacheValues()
105110
* @param hListener an initial MapListener that will receive all
106111
* the events from the ContinuousQueryCache,
107112
* including those corresponding to its initial
108113
* population
109114
* @param vTransformer the transformer that should be used to convert
110115
* values from the underlying cache before storing
111116
* them locally
117+
* Note: When parameter fCacheValues is false, it is inferred that provided parameter
118+
* listener is a lite listener as described by fLite parameter of
119+
* addMapListener(MapListener, Filter, boolean).
112120
*/
113121
ContinuousQueryCache(Supplier::View vCacheSupplier,
114122
Filter::View vFilter, bool fCacheValues,
@@ -169,6 +177,12 @@ class COH_EXPORT ContinuousQueryCache
169177
*
170178
* @return true if this object caches values locally, and false if it
171179
* relies on the underlying NamedCache
180+
*
181+
* Note: if addMapListener(MapListener, Filter, boolean) adds a standard
182+
* (non-lite) listener or a filter to this ObservableMap, cache values are
183+
* always maintained locally. The locally cached values are used to filter events
184+
* and to supply the old and new values for the events that it raises.
185+
* Additionally, a non-null transformer infers caches values being stored locally.
172186
*/
173187
virtual bool isCacheValues() const;
174188

@@ -182,7 +196,8 @@ class COH_EXPORT ContinuousQueryCache
182196
* cached data and rely on the underlying NamedCache.
183197
*
184198
* @param fCacheValues pass true to enable local caching, or false to
185-
* disable it
199+
* disable it. Override of false described
200+
* in isCacheValues()
186201
*/
187202
virtual void setCacheValues(bool fCacheValues);
188203

src/coherence/net/cache/ContinuousQueryCache.cpp

+9-6
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,8 @@ MapListener::View ContinuousQueryCache::getMapListener() const
248248

249249
bool ContinuousQueryCache::isCacheValues() const
250250
{
251-
return m_fCacheValues || isObserved();
251+
// standard listener or non-null transformer override initial fCacheValue
252+
return m_fCacheValues || isObserved() || f_vTransformer != NULL;
252253
}
253254

254255
void ContinuousQueryCache::setCacheValues(bool fCacheValues)
@@ -332,11 +333,13 @@ ObservableMap::Handle ContinuousQueryCache::ensureInternalCache() const
332333
if (hMapLocal == NULL)
333334
{
334335
hMapLocal = m_hMapLocal = instantiateInternalCache();
335-
if (m_fListeners)
336+
337+
MapListener::Handle hListener = m_hListener;
338+
bool fLite = !isCacheValues();
339+
if (hListener != NULL)
336340
{
337-
MapListener::Handle hListener = m_hListener;
338341
ensureEventQueue();
339-
hMapLocal->addFilterListener(instantiateEventRouter(m_hListener, false));
342+
hMapLocal->addFilterListener(instantiateEventRouter(hListener, fLite), NULL, fLite);
340343
}
341344
}
342345
return hMapLocal;
@@ -1584,8 +1587,8 @@ void ContinuousQueryCache::onInit()
15841587
initialize(f_hSetKeys, instantiateKeySet());
15851588
initialize(f_hSetEntries, instantiateEntrySet());
15861589

1587-
// was a listener passed at construction time?
1588-
m_fListeners = m_hListener != NULL;
1590+
// was a standard (non-lite) listener passed at construction time?
1591+
m_fListeners = m_hListener != NULL && isCacheValues();
15891592

15901593
ensureInternalCache();
15911594
ensureSynchronized(false);

tests/functional/coherence/net/cache/CQCProxyTest.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ class CQCProxyTest : public CxxTest::TestSuite
213213

214214
// instantiate the CQC, will start the test running.
215215
ContinuousQueryCache::Handle hCQC =
216-
ContinuousQueryCache::create(hTestCache, AlwaysFilter::create(), false, hListener);
216+
ContinuousQueryCache::create(hTestCache, AlwaysFilter::create(), true, hListener);
217217

218218
// add member listener to inner cache to receive memberLeft
219219
// event; intermittently, the "get" which restarts the

tests/functional/coherence/net/cache/ContinuousQueryCacheTest.hpp

+82-1
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,44 @@ class ContinuousQueryCacheTest : public CxxTest::TestSuite
122122
}
123123
};
124124

125+
// validating lite cache listener for CQC instance
126+
class ValidateLiteMapListener : public class_spec<ValidateLiteMapListener,
127+
extends<Object>, implements<MapListener> >
128+
{
129+
friend class factory<ValidateLiteMapListener>;
130+
131+
protected:
132+
ValidateLiteMapListener(bool fLite)
133+
{
134+
m_fLite = fLite;
135+
}
136+
137+
public:
138+
void entryInserted(MapEvent::View vEvt)
139+
{
140+
TS_ASSERT(m_fLite ? vEvt->getNewValue() == NULL : vEvt->getNewValue() != NULL);
141+
}
142+
143+
void entryUpdated(MapEvent::View vEvt)
144+
{
145+
TS_ASSERT(m_fLite ? vEvt->getNewValue() == NULL : vEvt->getNewValue() != NULL);
146+
TS_ASSERT(m_fLite ? vEvt->getOldValue() == NULL : vEvt->getOldValue() != NULL);
147+
}
148+
149+
void entryDeleted(MapEvent::View vEvt)
150+
{
151+
TS_ASSERT(m_fLite ? vEvt->getOldValue() == NULL : vEvt->getOldValue() != NULL);
152+
}
153+
154+
// ----- data members -----------------------------------------------
155+
156+
protected:
157+
/**
158+
* If true, validate a lite MapListener, get old and new value are NULL.
159+
*/
160+
bool m_fLite;
161+
};
162+
125163
// ----- local class: TestCQCListener -----------------------------------
126164

127165
/**
@@ -510,7 +548,7 @@ class ContinuousQueryCacheTest : public CxxTest::TestSuite
510548

511549
// create CQC
512550
ContinuousQueryCache::Handle hCqc = ContinuousQueryCache::create(
513-
hCache, AlwaysFilter::create(), false, hMockListener);
551+
hCache, AlwaysFilter::create(), true, hMockListener);
514552

515553
Object::View vKey = String::create("key1");
516554
Object::View vVal = String::create("val1");
@@ -1891,6 +1929,49 @@ class ContinuousQueryCacheTest : public CxxTest::TestSuite
18911929
hCqc->release();
18921930
}
18931931

1932+
/*
1933+
* Test for COH-31325
1934+
*/
1935+
void testCOH31325()
1936+
{
1937+
NamedCache::Handle hCache = ensureCleanCache("TestCache");
1938+
1939+
// test fCacheValues of false and lite map listener
1940+
ContinuousQueryCache::Handle hCqc = ContinuousQueryCache::create(
1941+
hCache, AlwaysFilter::create(), false, ValidateLiteMapListener::create(true));
1942+
TS_ASSERT(!hCqc->isCacheValues());
1943+
hCache->put(String::create("Key31325"), String::create("Value31325"));
1944+
hCache->put(String::create("Key31325"), String::create("UpdateValue31325"));
1945+
hCache->remove(String::create("Key31325"));
1946+
TS_ASSERT(!hCqc->isCacheValues());
1947+
hCqc->release();
1948+
1949+
// test fCacheValues of false initially with map listener, first non-lite listener converts isCacheValues to true
1950+
hCqc = ContinuousQueryCache::create(
1951+
hCache, AlwaysFilter::create(), false, SampleMapListener::create());
1952+
TS_ASSERT(!hCqc->isCacheValues());
1953+
hCache->put(String::create("Key31325"), String::create("Value31325"));
1954+
hCache->put(String::create("Key31325"), String::create("UpdateValue31325"));
1955+
hCache->remove(String::create("Key31325"));
1956+
TS_ASSERT(!hCqc->isCacheValues());
1957+
// add a standard listener and verify isCacheValues after
1958+
hCqc->addFilterListener(ValidateLiteMapListener::create(false), AlwaysFilter::create(), false);
1959+
hCache->put(String::create("Key31325"), String::create("SecondUpdateValue31325"));
1960+
TS_ASSERT(hCqc->isCacheValues());
1961+
hCqc->release();
1962+
1963+
// validate standard listener when fCacheValues is true
1964+
hCache = ensureCleanCache("TestCache");
1965+
hCqc = ContinuousQueryCache::create(
1966+
hCache, AlwaysFilter::create(), true, ValidateLiteMapListener::create(false));
1967+
TS_ASSERT(hCqc->isCacheValues());
1968+
hCache->put(String::create("Key31325"), String::create("Value31325"));
1969+
hCache->put(String::create("Key31325"), String::create("UpdateValue31325"));
1970+
hCache->remove(String::create("Key31325"));
1971+
TS_ASSERT(hCqc->isCacheValues());
1972+
hCqc->release();
1973+
}
1974+
18941975
/*
18951976
* Test for COH-10013
18961977
*/

tests/unit/coherence/net/ViewBuilderTest.hpp

+6
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,12 @@ class ViewBuilderTest : public CxxTest::TestSuite
154154
hCache->entrySet((Filter::View) NULL);
155155
hCache->lastExpectation()->ignoreArguments();
156156
hCache->setObjectReturn(HashSet::create());
157+
hCache->invokeAll((Filter::View) NULL, (InvocableMap::EntryProcessor::Handle) NULL);
158+
hCache->lastExpectation()->ignoreArguments();
159+
hCache->setObjectReturn(HashMap::create());
160+
hCache->getAll((Collection::View) NULL);
161+
hCache->lastExpectation()->ignoreArguments();
162+
hCache->setObjectReturn(HashSet::create());
157163

158164
//replay
159165
hCache->replay();

tests/unit/coherence/net/cache/ContinuousQueryCacheTest.hpp

+34
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,40 @@ class ContinuousQueryCacheTest : public CxxTest::TestSuite
9696
TS_ASSERT(hCqc->isCacheValues());
9797
}
9898

99+
void testIsCacheValuesWithListener()
100+
{
101+
MockNamedCache::Handle hMockNamedCache = MockNamedCache::create();
102+
MockMapListener::Handle hMockListener = MockMapListener::create();
103+
Filter::Handle hFilter = DummyFilter::create();
104+
105+
//set expectations
106+
hMockNamedCache->entrySet(hFilter);
107+
hMockNamedCache->setMatcher(&matchAll);
108+
hMockNamedCache->setObjectReturn(Collections::emptySet());
109+
110+
hMockNamedCache->keySet(hFilter);
111+
hMockNamedCache->setMatcher(&matchAll);
112+
hMockNamedCache->setObjectReturn(Collections::emptySet());
113+
114+
hMockNamedCache->entrySet(hFilter);
115+
hMockNamedCache->setMatcher(&matchAll);
116+
hMockNamedCache->setObjectReturn(Collections::emptySet());
117+
118+
hMockNamedCache->keySet(hFilter);
119+
hMockNamedCache->setMatcher(&matchAll);
120+
hMockNamedCache->setObjectReturn(Collections::emptySet());
121+
122+
//replay
123+
hMockNamedCache->replay();
124+
125+
ContinuousQueryCache::Handle hCqc = ContinuousQueryCache::create(hMockNamedCache, hFilter, false, hMockListener);
126+
TS_ASSERT(!hCqc->isCacheValues());
127+
128+
hCqc = ContinuousQueryCache::create(hMockNamedCache, hFilter, true, hMockListener);
129+
TS_ASSERT(hCqc->isCacheValues());
130+
}
131+
132+
99133

100134
void testSetCacheValues()
101135
{

0 commit comments

Comments
 (0)