Skip to content

Commit

Permalink
Bug 37315344 - [37264961->14.1.2.0.1] CQC constructor with fCacheValu…
Browse files Browse the repository at this point in the history
…es 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]
  • Loading branch information
jfialli committed Dec 5, 2024
1 parent e0b29f9 commit e038900
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 11 deletions.
21 changes: 18 additions & 3 deletions include/public/coherence/net/cache/ContinuousQueryCache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,18 @@ class COH_EXPORT ContinuousQueryCache
* @param vFilter the Filter that defines the view
* @param fCacheValues pass true to cache both the keys and values of
* the materialized view locally, or false to
* only cache the keys
* only cache the keys. Override of false described
* in isCacheValues()
* @param hListener an initial MapListener that will receive all
* the events from the ContinuousQueryCache,
* including those corresponding to its initial
* population
* @param vTransformer the transformer that should be used to convert
* values from the underlying cache before storing
* them locally
* Note: When parameter fCacheValues is false, it is inferred that provided parameter
* listener is a lite listener as described by fLite parameter of
* addMapListener(MapListener, Filter, boolean).
*/
ContinuousQueryCache(NamedCache::Handle hCache,
Filter::View vFilter, bool fCacheValues = false,
Expand All @@ -101,14 +105,18 @@ class COH_EXPORT ContinuousQueryCache
* @param vFilter the Filter that defines the view
* @param fCacheValues pass true to cache both the keys and values of
* the materialized view locally, or false to
* only cache the keys
* only cache the keys. Override of false described
* in isCacheValues()
* @param hListener an initial MapListener that will receive all
* the events from the ContinuousQueryCache,
* including those corresponding to its initial
* population
* @param vTransformer the transformer that should be used to convert
* values from the underlying cache before storing
* them locally
* Note: When parameter fCacheValues is false, it is inferred that provided parameter
* listener is a lite listener as described by fLite parameter of
* addMapListener(MapListener, Filter, boolean).
*/
ContinuousQueryCache(Supplier::View vCacheSupplier,
Filter::View vFilter, bool fCacheValues,
Expand Down Expand Up @@ -169,6 +177,12 @@ class COH_EXPORT ContinuousQueryCache
*
* @return true if this object caches values locally, and false if it
* relies on the underlying NamedCache
*
* Note: if addMapListener(MapListener, Filter, boolean) adds a standard
* (non-lite) listener or a filter to this ObservableMap, cache values are
* always maintained locally. The locally cached values are used to filter events
* and to supply the old and new values for the events that it raises.
* Additionally, a non-null transformer infers caches values being stored locally.
*/
virtual bool isCacheValues() const;

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

Expand Down
15 changes: 9 additions & 6 deletions src/coherence/net/cache/ContinuousQueryCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ MapListener::View ContinuousQueryCache::getMapListener() const

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

void ContinuousQueryCache::setCacheValues(bool fCacheValues)
Expand Down Expand Up @@ -332,11 +333,13 @@ ObservableMap::Handle ContinuousQueryCache::ensureInternalCache() const
if (hMapLocal == NULL)
{
hMapLocal = m_hMapLocal = instantiateInternalCache();
if (m_fListeners)

MapListener::Handle hListener = m_hListener;
bool fLite = !isCacheValues();
if (hListener != NULL)
{
MapListener::Handle hListener = m_hListener;
ensureEventQueue();
hMapLocal->addFilterListener(instantiateEventRouter(m_hListener, false));
hMapLocal->addFilterListener(instantiateEventRouter(hListener, fLite), NULL, fLite);
}
}
return hMapLocal;
Expand Down Expand Up @@ -1584,8 +1587,8 @@ void ContinuousQueryCache::onInit()
initialize(f_hSetKeys, instantiateKeySet());
initialize(f_hSetEntries, instantiateEntrySet());

// was a listener passed at construction time?
m_fListeners = m_hListener != NULL;
// was a standard (non-lite) listener passed at construction time?
m_fListeners = m_hListener != NULL && isCacheValues();

ensureInternalCache();
ensureSynchronized(false);
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/coherence/net/cache/CQCProxyTest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ class CQCProxyTest : public CxxTest::TestSuite

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

// add member listener to inner cache to receive memberLeft
// event; intermittently, the "get" which restarts the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,44 @@ class ContinuousQueryCacheTest : public CxxTest::TestSuite
}
};

// validating lite cache listener for CQC instance
class ValidateLiteMapListener : public class_spec<ValidateLiteMapListener,
extends<Object>, implements<MapListener> >
{
friend class factory<ValidateLiteMapListener>;

protected:
ValidateLiteMapListener(bool fLite)
{
m_fLite = fLite;
}

public:
void entryInserted(MapEvent::View vEvt)
{
TS_ASSERT(m_fLite ? vEvt->getNewValue() == NULL : vEvt->getNewValue() != NULL);
}

void entryUpdated(MapEvent::View vEvt)
{
TS_ASSERT(m_fLite ? vEvt->getNewValue() == NULL : vEvt->getNewValue() != NULL);
TS_ASSERT(m_fLite ? vEvt->getOldValue() == NULL : vEvt->getOldValue() != NULL);
}

void entryDeleted(MapEvent::View vEvt)
{
TS_ASSERT(m_fLite ? vEvt->getOldValue() == NULL : vEvt->getOldValue() != NULL);
}

// ----- data members -----------------------------------------------

protected:
/**
* If true, validate a lite MapListener, get old and new value are NULL.
*/
bool m_fLite;
};

// ----- local class: TestCQCListener -----------------------------------

/**
Expand Down Expand Up @@ -510,7 +548,7 @@ class ContinuousQueryCacheTest : public CxxTest::TestSuite

// create CQC
ContinuousQueryCache::Handle hCqc = ContinuousQueryCache::create(
hCache, AlwaysFilter::create(), false, hMockListener);
hCache, AlwaysFilter::create(), true, hMockListener);

Object::View vKey = String::create("key1");
Object::View vVal = String::create("val1");
Expand Down Expand Up @@ -1891,6 +1929,49 @@ class ContinuousQueryCacheTest : public CxxTest::TestSuite
hCqc->release();
}

/*
* Test for COH-31325
*/
void testCOH31325()
{
NamedCache::Handle hCache = ensureCleanCache("TestCache");

// test fCacheValues of false and lite map listener
ContinuousQueryCache::Handle hCqc = ContinuousQueryCache::create(
hCache, AlwaysFilter::create(), false, ValidateLiteMapListener::create(true));
TS_ASSERT(!hCqc->isCacheValues());
hCache->put(String::create("Key31325"), String::create("Value31325"));
hCache->put(String::create("Key31325"), String::create("UpdateValue31325"));
hCache->remove(String::create("Key31325"));
TS_ASSERT(!hCqc->isCacheValues());
hCqc->release();

// test fCacheValues of false initially with map listener, first non-lite listener converts isCacheValues to true
hCqc = ContinuousQueryCache::create(
hCache, AlwaysFilter::create(), false, SampleMapListener::create());
TS_ASSERT(!hCqc->isCacheValues());
hCache->put(String::create("Key31325"), String::create("Value31325"));
hCache->put(String::create("Key31325"), String::create("UpdateValue31325"));
hCache->remove(String::create("Key31325"));
TS_ASSERT(!hCqc->isCacheValues());
// add a standard listener and verify isCacheValues after
hCqc->addFilterListener(ValidateLiteMapListener::create(false), AlwaysFilter::create(), false);
hCache->put(String::create("Key31325"), String::create("SecondUpdateValue31325"));
TS_ASSERT(hCqc->isCacheValues());
hCqc->release();

// validate standard listener when fCacheValues is true
hCache = ensureCleanCache("TestCache");
hCqc = ContinuousQueryCache::create(
hCache, AlwaysFilter::create(), true, ValidateLiteMapListener::create(false));
TS_ASSERT(hCqc->isCacheValues());
hCache->put(String::create("Key31325"), String::create("Value31325"));
hCache->put(String::create("Key31325"), String::create("UpdateValue31325"));
hCache->remove(String::create("Key31325"));
TS_ASSERT(hCqc->isCacheValues());
hCqc->release();
}

/*
* Test for COH-10013
*/
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/coherence/net/ViewBuilderTest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ class ViewBuilderTest : public CxxTest::TestSuite
hCache->entrySet((Filter::View) NULL);
hCache->lastExpectation()->ignoreArguments();
hCache->setObjectReturn(HashSet::create());
hCache->invokeAll((Filter::View) NULL, (InvocableMap::EntryProcessor::Handle) NULL);
hCache->lastExpectation()->ignoreArguments();
hCache->setObjectReturn(HashMap::create());
hCache->getAll((Collection::View) NULL);
hCache->lastExpectation()->ignoreArguments();
hCache->setObjectReturn(HashSet::create());

//replay
hCache->replay();
Expand Down
34 changes: 34 additions & 0 deletions tests/unit/coherence/net/cache/ContinuousQueryCacheTest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,40 @@ class ContinuousQueryCacheTest : public CxxTest::TestSuite
TS_ASSERT(hCqc->isCacheValues());
}

void testIsCacheValuesWithListener()
{
MockNamedCache::Handle hMockNamedCache = MockNamedCache::create();
MockMapListener::Handle hMockListener = MockMapListener::create();
Filter::Handle hFilter = DummyFilter::create();

//set expectations
hMockNamedCache->entrySet(hFilter);
hMockNamedCache->setMatcher(&matchAll);
hMockNamedCache->setObjectReturn(Collections::emptySet());

hMockNamedCache->keySet(hFilter);
hMockNamedCache->setMatcher(&matchAll);
hMockNamedCache->setObjectReturn(Collections::emptySet());

hMockNamedCache->entrySet(hFilter);
hMockNamedCache->setMatcher(&matchAll);
hMockNamedCache->setObjectReturn(Collections::emptySet());

hMockNamedCache->keySet(hFilter);
hMockNamedCache->setMatcher(&matchAll);
hMockNamedCache->setObjectReturn(Collections::emptySet());

//replay
hMockNamedCache->replay();

ContinuousQueryCache::Handle hCqc = ContinuousQueryCache::create(hMockNamedCache, hFilter, false, hMockListener);
TS_ASSERT(!hCqc->isCacheValues());

hCqc = ContinuousQueryCache::create(hMockNamedCache, hFilter, true, hMockListener);
TS_ASSERT(hCqc->isCacheValues());
}



void testSetCacheValues()
{
Expand Down

0 comments on commit e038900

Please sign in to comment.