IDEMPIERE-2698 Performance: Report checking for zoom condition on dat… (#59)
* IDEMPIERE-2698 Performance: Report checking for zoom condition on database - must be cached Add unit testing * IDEMPIERE-2699 Performance: Constant visits to database for MTable not cached Should usually access from tenant instead system client.
This commit is contained in:
parent
1a902a95de
commit
ce107f3678
|
@ -40,6 +40,7 @@ import org.junit.jupiter.api.AfterAll;
|
|||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.TestInfo;
|
||||
|
||||
/**
|
||||
* @author hengsin
|
||||
|
@ -57,26 +58,42 @@ public abstract class AbstractTestCase {
|
|||
protected final int GARDEN_WORLD_HQ_WAREHOUSE = 103;
|
||||
|
||||
@BeforeAll
|
||||
/**
|
||||
* setup for class
|
||||
*/
|
||||
static void setup() {
|
||||
Adempiere.startup(false);
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
protected void init() {
|
||||
/**
|
||||
* Init for each test method
|
||||
* @param testInfo
|
||||
*/
|
||||
protected void init(TestInfo testInfo) {
|
||||
String trxName = Trx.createTrxName(getClass().getName()+"_");
|
||||
trx = Trx.get(trxName, true);
|
||||
trx.start();
|
||||
|
||||
initContext();
|
||||
initContext(testInfo);
|
||||
}
|
||||
|
||||
protected LoginDetails newLoginDetails() {
|
||||
/**
|
||||
* Create the login context for each test method
|
||||
* @param testInfo
|
||||
* @return LoginDetails
|
||||
*/
|
||||
protected LoginDetails newLoginDetails(TestInfo testInfo) {
|
||||
return new LoginDetails(GARDEN_WORLD_CLIENT, GARDEN_WORLD_HQ_ORG, GARDEN_WORLD_ADMIN_USER, GARDEN_WORLD_ADMIN_ROLE, GARDEN_WORLD_HQ_WAREHOUSE,
|
||||
new Timestamp(System.currentTimeMillis()), Language.getLanguage("en_US"));
|
||||
}
|
||||
|
||||
protected void initContext() {
|
||||
loginDetails = newLoginDetails();
|
||||
/**
|
||||
* Init environment context for each test method
|
||||
* @param testInfo
|
||||
*/
|
||||
protected void initContext(TestInfo testInfo) {
|
||||
loginDetails = newLoginDetails(testInfo);
|
||||
|
||||
Env.setContext(Env.getCtx(), Env.AD_CLIENT_ID, loginDetails.getClientId());
|
||||
Env.setContext(Env.getCtx(), Env.AD_ORG_ID, loginDetails.getOrganizationId());
|
||||
|
@ -125,6 +142,9 @@ public abstract class AbstractTestCase {
|
|||
}
|
||||
|
||||
@AfterEach
|
||||
/**
|
||||
* tear down for each test method
|
||||
*/
|
||||
protected void tearDown() {
|
||||
if (trx != null && trx.isActive()) {
|
||||
trx.rollback();
|
||||
|
@ -132,10 +152,17 @@ public abstract class AbstractTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return current transaction
|
||||
*/
|
||||
protected Trx getTrx() {
|
||||
return trx;
|
||||
}
|
||||
|
||||
/**
|
||||
* commit current transaction
|
||||
*/
|
||||
protected void commit() {
|
||||
if (trx != null && trx.isActive()) {
|
||||
try {
|
||||
|
@ -146,6 +173,9 @@ public abstract class AbstractTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* rollback current transaction
|
||||
*/
|
||||
protected void rollback() {
|
||||
if (trx != null && trx.isActive()) {
|
||||
trx.rollback();
|
||||
|
@ -180,11 +210,18 @@ public abstract class AbstractTestCase {
|
|||
return loginDetails.getLoginDate();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return current transaction name
|
||||
*/
|
||||
protected String getTrxName() {
|
||||
return trx.getTrxName();
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
/**
|
||||
* shutdown for class
|
||||
*/
|
||||
static void shutdown() {
|
||||
Adempiere.stop();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
/***********************************************************************
|
||||
* This file is part of iDempiere ERP Open Source *
|
||||
* http://www.idempiere.org *
|
||||
* *
|
||||
* Copyright (C) Contributors *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License *
|
||||
* as published by the Free Software Foundation; either version 2 *
|
||||
* of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the Free Software *
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, *
|
||||
* MA 02110-1301, USA. *
|
||||
* *
|
||||
* Contributors: *
|
||||
* - hengsin *
|
||||
**********************************************************************/
|
||||
package org.idempiere.test.performance;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.compiere.model.MOrder;
|
||||
import org.compiere.model.MZoomCondition;
|
||||
import org.compiere.util.CacheMgt;
|
||||
import org.idempiere.test.AbstractTestCase;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author hengsin
|
||||
*
|
||||
*/
|
||||
public class CacheTest extends AbstractTestCase {
|
||||
|
||||
public CacheTest() {
|
||||
}
|
||||
|
||||
@Test
|
||||
/**
|
||||
* https://idempiere.atlassian.net/browse/IDEMPIERE-2698
|
||||
*/
|
||||
public void testZoomConditionCache() {
|
||||
MZoomCondition[] conditions1 = MZoomCondition.getConditions(MOrder.Table_ID);
|
||||
assertTrue(conditions1 != null && conditions1.length > 0);
|
||||
MZoomCondition[] conditions2 = MZoomCondition.getConditions(MOrder.Table_ID);
|
||||
assertTrue(conditions2 != null && conditions2.length > 0);
|
||||
assertTrue(conditions1 == conditions2);
|
||||
CacheMgt.get().reset();
|
||||
MZoomCondition[] conditions3 = MZoomCondition.getConditions(MOrder.Table_ID);
|
||||
assertTrue(conditions3 != null && conditions3.length == conditions1.length);
|
||||
assertTrue(conditions1 != conditions3);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue