IDEMPIERE-4764 Hazelcast distributed cache can be an issue in some environments (#682)

- Fix cache reset and unit test bugs
This commit is contained in:
hengsin 2021-05-11 20:18:48 +08:00 committed by GitHub
parent 4439a74c52
commit 0da2eb5bd2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 5 deletions

View File

@ -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

View File

@ -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());