From 0da2eb5bd2cce3ccb6fa15b2c106a08470f557cb Mon Sep 17 00:00:00 2001 From: hengsin Date: Tue, 11 May 2021 20:18:48 +0800 Subject: [PATCH] IDEMPIERE-4764 Hazelcast distributed cache can be an issue in some environments (#682) - Fix cache reset and unit test bugs --- org.adempiere.base/src/org/compiere/model/PO.java | 4 ++-- .../src/org/idempiere/test/performance/CacheTest.java | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/org.adempiere.base/src/org/compiere/model/PO.java b/org.adempiere.base/src/org/compiere/model/PO.java index ae9e955b7e..052d21c115 100644 --- a/org.adempiere.base/src/org/compiere/model/PO.java +++ b/org.adempiere.base/src/org/compiere/model/PO.java @@ -2456,7 +2456,7 @@ public abstract class PO m_createNew = false; } if (!newRecord) { - Adempiere.getThreadPoolExecutor().submit(() -> CacheMgt.get().reset(p_info.getTableName())); + Adempiere.getThreadPoolExecutor().submit(() -> CacheMgt.get().reset(p_info.getTableName(), get_ID())); MRecentItem.clearLabel(p_info.getAD_Table_ID(), get_ID()); } else if (get_ID() > 0 && success) Adempiere.getThreadPoolExecutor().submit(() -> CacheMgt.get().newRecord(p_info.getTableName(), get_ID())); @@ -3640,7 +3640,7 @@ public abstract class PO int size = p_info.getColumnCount(); m_oldValues = new Object[size]; m_newValues = new Object[size]; - Adempiere.getThreadPoolExecutor().submit(() -> CacheMgt.get().reset(p_info.getTableName())); + Adempiere.getThreadPoolExecutor().submit(() -> CacheMgt.get().reset(p_info.getTableName(), Record_ID)); } } finally diff --git a/org.idempiere.test/src/org/idempiere/test/performance/CacheTest.java b/org.idempiere.test/src/org/idempiere/test/performance/CacheTest.java index ae6aeaf206..68c6d6b484 100644 --- a/org.idempiere.test/src/org/idempiere/test/performance/CacheTest.java +++ b/org.idempiere.test/src/org/idempiere/test/performance/CacheTest.java @@ -180,7 +180,7 @@ public class CacheTest extends AbstractTestCase { @SuppressWarnings({"unchecked"}) @Test - public void testPOCacheAfterUpdate() { + public void testPOCacheAfterUpdate() throws InterruptedException { int mulch = 137; int oak = 123; //init cache @@ -212,16 +212,18 @@ public class CacheTest extends AbstractTestCase { p2.saveEx(); //get after p2 update, miss should increase + //wait 500ms since cache reset after update is async + Thread.sleep(500); miss = pc.getMiss(); p2 = MProduct.get(Env.getCtx(), oak); assertEquals(oak, p2.getM_Product_ID()); - assertTrue(pc.getMiss() > miss, "Get of product Oak after update of product Oak, cache miss should increase"); + assertTrue(pc.getMiss() > miss, "Get of product Oak after update of product Oak, cache miss should increase. before="+miss+" after="+pc.getMiss()); //cache for p1 not effected by p2 update, hit should increase hit = pc.getHit(); p1 = MProduct.get(Env.getCtx(), mulch); assertEquals(mulch, p1.getM_Product_ID()); - assertTrue(pc.getHit() > hit, "Get of product Mulch after update of product Oak, cache hit should increase"); + assertTrue(pc.getHit() > hit, "Get of product Mulch after update of product Oak, cache hit should increase. before="+hit+" after="+pc.getHit()); //create p3 to test delete MProduct p3 = new MProduct(Env.getCtx(), 0, getTrxName());