1
|
/**
|
2
|
* Copyright (C) 2009 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
|
10
|
package eu.etaxonomy.cdm.persistence.dao.hibernate.taxon;
|
11
|
|
12
|
import static junit.framework.Assert.assertNotNull;
|
13
|
|
14
|
import java.util.UUID;
|
15
|
|
16
|
import org.junit.After;
|
17
|
import org.junit.Before;
|
18
|
import org.junit.Test;
|
19
|
import org.unitils.dbunit.annotation.DataSet;
|
20
|
import org.unitils.spring.annotation.SpringBeanByType;
|
21
|
|
22
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
23
|
import eu.etaxonomy.cdm.model.view.context.AuditEventContextHolder;
|
24
|
import eu.etaxonomy.cdm.persistence.dao.common.IDefinedTermDao;
|
25
|
import eu.etaxonomy.cdm.persistence.dao.reference.IReferenceDao;
|
26
|
import eu.etaxonomy.cdm.persistence.dao.taxon.ITaxonDao;
|
27
|
import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
|
28
|
|
29
|
/**
|
30
|
* @author a.mueller
|
31
|
* @author ben.clark
|
32
|
*
|
33
|
*/
|
34
|
public class TaxonDaoHibernateImplBenchmark extends CdmTransactionalIntegrationTest {
|
35
|
|
36
|
// @Rule
|
37
|
// public MethodRule benchmarkRun = new BenchmarkRule();
|
38
|
|
39
|
|
40
|
@SpringBeanByType
|
41
|
private ITaxonDao taxonDao;
|
42
|
|
43
|
|
44
|
@SpringBeanByType
|
45
|
private IReferenceDao referenceDao;
|
46
|
|
47
|
@SpringBeanByType
|
48
|
IDefinedTermDao definedTermDao;
|
49
|
|
50
|
private UUID acherontiaLachesis;
|
51
|
|
52
|
private static final int BENCHMARK_ROUNDS = 20;
|
53
|
|
54
|
@Before
|
55
|
public void setUp() {
|
56
|
acherontiaLachesis = UUID.fromString("b04cc9cb-2b4a-4cc4-a94a-3c93a2158b06");
|
57
|
}
|
58
|
|
59
|
@After
|
60
|
public void tearDown() {
|
61
|
AuditEventContextHolder.clearContext();
|
62
|
}
|
63
|
|
64
|
/**
|
65
|
* Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.taxon.TaxonDaoHibernateImpl#TaxonDaoHibernateImpl()}.
|
66
|
*/
|
67
|
@Test
|
68
|
@DataSet(value="TaxonDaoHibernateImplTest.xml")
|
69
|
public void testInit() {
|
70
|
logger.warn("testInit()");
|
71
|
assertNotNull("Instance of ITaxonDao expected",taxonDao);
|
72
|
assertNotNull("Instance of IReferenceDao expected",referenceDao);
|
73
|
}
|
74
|
|
75
|
@Test
|
76
|
@DataSet(value="TaxonDaoHibernateImplTest.xml")
|
77
|
public void updateTaxon() {
|
78
|
|
79
|
Taxon taxon = (Taxon) taxonDao.findByUuid(acherontiaLachesis);
|
80
|
|
81
|
long startMillis = System.currentTimeMillis();
|
82
|
for(int indx = 0; indx < BENCHMARK_ROUNDS; indx++){
|
83
|
taxon.setTitleCache("Acherontia lachesis benchmark_" + indx + " Eitschberger, 2003", true);
|
84
|
taxonDao.saveOrUpdate(taxon);
|
85
|
logger.debug("[" + indx + "]" + taxon.getTitleCache());
|
86
|
}
|
87
|
double duration = ((double)(System.currentTimeMillis() - startMillis) ) / BENCHMARK_ROUNDS ;
|
88
|
logger.info("Benchmark result - [update one Taxon] : " + duration + "ms (" + BENCHMARK_ROUNDS +" benchmark rounds )");
|
89
|
}
|
90
|
|
91
|
|
92
|
|
93
|
|
94
|
|
95
|
|
96
|
|
97
|
|
98
|
|
99
|
|
100
|
|
101
|
|
102
|
|
103
|
|
104
|
|
105
|
|
106
|
|
107
|
|
108
|
|
109
|
|
110
|
}
|