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.AfterEach;
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.TestInfo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author hengsin
|
* @author hengsin
|
||||||
|
@ -57,26 +58,42 @@ public abstract class AbstractTestCase {
|
||||||
protected final int GARDEN_WORLD_HQ_WAREHOUSE = 103;
|
protected final int GARDEN_WORLD_HQ_WAREHOUSE = 103;
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
|
/**
|
||||||
|
* setup for class
|
||||||
|
*/
|
||||||
static void setup() {
|
static void setup() {
|
||||||
Adempiere.startup(false);
|
Adempiere.startup(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
protected void init() {
|
/**
|
||||||
|
* Init for each test method
|
||||||
|
* @param testInfo
|
||||||
|
*/
|
||||||
|
protected void init(TestInfo testInfo) {
|
||||||
String trxName = Trx.createTrxName(getClass().getName()+"_");
|
String trxName = Trx.createTrxName(getClass().getName()+"_");
|
||||||
trx = Trx.get(trxName, true);
|
trx = Trx.get(trxName, true);
|
||||||
trx.start();
|
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,
|
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"));
|
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_CLIENT_ID, loginDetails.getClientId());
|
||||||
Env.setContext(Env.getCtx(), Env.AD_ORG_ID, loginDetails.getOrganizationId());
|
Env.setContext(Env.getCtx(), Env.AD_ORG_ID, loginDetails.getOrganizationId());
|
||||||
|
@ -125,6 +142,9 @@ public abstract class AbstractTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterEach
|
@AfterEach
|
||||||
|
/**
|
||||||
|
* tear down for each test method
|
||||||
|
*/
|
||||||
protected void tearDown() {
|
protected void tearDown() {
|
||||||
if (trx != null && trx.isActive()) {
|
if (trx != null && trx.isActive()) {
|
||||||
trx.rollback();
|
trx.rollback();
|
||||||
|
@ -132,10 +152,17 @@ public abstract class AbstractTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return current transaction
|
||||||
|
*/
|
||||||
protected Trx getTrx() {
|
protected Trx getTrx() {
|
||||||
return trx;
|
return trx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* commit current transaction
|
||||||
|
*/
|
||||||
protected void commit() {
|
protected void commit() {
|
||||||
if (trx != null && trx.isActive()) {
|
if (trx != null && trx.isActive()) {
|
||||||
try {
|
try {
|
||||||
|
@ -146,6 +173,9 @@ public abstract class AbstractTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* rollback current transaction
|
||||||
|
*/
|
||||||
protected void rollback() {
|
protected void rollback() {
|
||||||
if (trx != null && trx.isActive()) {
|
if (trx != null && trx.isActive()) {
|
||||||
trx.rollback();
|
trx.rollback();
|
||||||
|
@ -180,11 +210,18 @@ public abstract class AbstractTestCase {
|
||||||
return loginDetails.getLoginDate();
|
return loginDetails.getLoginDate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return current transaction name
|
||||||
|
*/
|
||||||
protected String getTrxName() {
|
protected String getTrxName() {
|
||||||
return trx.getTrxName();
|
return trx.getTrxName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterAll
|
@AfterAll
|
||||||
|
/**
|
||||||
|
* shutdown for class
|
||||||
|
*/
|
||||||
static void shutdown() {
|
static void shutdown() {
|
||||||
Adempiere.stop();
|
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