Project

General

Profile

Download (5.2 KB) Statistics
| Branch: | Tag: | Revision:
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.ArrayList;
15
import java.util.List;
16
import java.util.UUID;
17

    
18
import org.junit.After;
19
import org.junit.Before;
20
import org.junit.Test;
21
import org.unitils.dbunit.annotation.DataSet;
22
import org.unitils.spring.annotation.SpringBeanByType;
23

    
24
import eu.etaxonomy.cdm.model.taxon.Taxon;
25
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
26
import eu.etaxonomy.cdm.model.view.AuditEvent;
27
import eu.etaxonomy.cdm.model.view.context.AuditEventContextHolder;
28
import eu.etaxonomy.cdm.persistence.dao.common.IDefinedTermDao;
29
import eu.etaxonomy.cdm.persistence.dao.reference.IReferenceDao;
30
import eu.etaxonomy.cdm.persistence.dao.taxon.IClassificationDao;
31
import eu.etaxonomy.cdm.persistence.dao.taxon.ITaxonDao;
32
import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
33

    
34
/**
35
 * @author a.mueller
36
 * @author ben.clark
37
 *
38
 */
39
public class TaxonDaoHibernateImplBenchmark extends CdmTransactionalIntegrationTest {
40

    
41
//    @Rule
42
//    public MethodRule benchmarkRun = new BenchmarkRule();
43

    
44

    
45
    @SpringBeanByType
46
    private ITaxonDao taxonDao;
47

    
48
    @SpringBeanByType
49
    private IClassificationDao classificationDao;
50

    
51
    @SpringBeanByType
52
    private IReferenceDao referenceDao;
53

    
54
    @SpringBeanByType
55
    IDefinedTermDao definedTermDao;
56

    
57
    private UUID uuid;
58
    private UUID sphingidae;
59
    private UUID acherontia;
60
    private UUID mimas;
61
    private UUID rethera;
62
    private UUID retheraSecCdmtest;
63
    private UUID atroposAgassiz;
64
    private UUID atroposLeach;
65
    private UUID acherontiaLachesis;
66
    private AuditEvent previousAuditEvent;
67
    private AuditEvent mostRecentAuditEvent;
68

    
69
    private UUID northernAmericaUuid;
70
    private UUID southernAmericaUuid;
71
    private UUID antarcticaUuid;
72

    
73
    private UUID classificationUuid;
74

    
75
    private Taxon taxonAcherontia;
76

    
77
    private static final int BENCHMARK_ROUNDS = 20;
78

    
79
    @Before
80
    public void setUp() {
81

    
82
        uuid = UUID.fromString("496b1325-be50-4b0a-9aa2-3ecd610215f2");
83
        sphingidae = UUID.fromString("54e767ee-894e-4540-a758-f906ecb4e2d9");
84
        acherontia = UUID.fromString("c5cc8674-4242-49a4-aada-72d63194f5fa");
85
        acherontiaLachesis = UUID.fromString("b04cc9cb-2b4a-4cc4-a94a-3c93a2158b06");
86
        atroposAgassiz = UUID.fromString("d75b2e3d-7394-4ada-b6a5-93175b8751c1");
87
        atroposLeach =  UUID.fromString("3da4ab34-6c50-4586-801e-732615899b07");
88
        rethera = UUID.fromString("a9f42927-e507-4fda-9629-62073a908aae");
89
        retheraSecCdmtest = UUID.fromString("a9f42927-e507-433a-9629-62073a908aae");
90

    
91

    
92
        mimas = UUID.fromString("900052b7-b69c-4e26-a8f0-01c215214c40");
93
        previousAuditEvent = new AuditEvent();
94
        previousAuditEvent.setRevisionNumber(1025);
95
        previousAuditEvent.setUuid(UUID.fromString("a680fab4-365e-4765-b49e-768f2ee30cda"));
96
        mostRecentAuditEvent = new AuditEvent();
97
        mostRecentAuditEvent.setRevisionNumber(1026);
98
        mostRecentAuditEvent.setUuid(UUID.fromString("afe8e761-8545-497b-9134-6a6791fc0b0d"));
99
        AuditEventContextHolder.clearContext(); // By default we're in the current view (i.e. view == null)
100

    
101
        northernAmericaUuid = UUID.fromString("2757e726-d897-4546-93bd-7951d203bf6f");
102
        southernAmericaUuid = UUID.fromString("6310b3ba-96f4-4855-bb5b-326e7af188ea");
103
        antarcticaUuid = UUID.fromString("791b3aa0-54dd-4bed-9b68-56b4680aad0c");
104

    
105
        classificationUuid = UUID.fromString("aeee7448-5298-4991-b724-8d5b75a0a7a9");
106

    
107
        taxonAcherontia = (Taxon)taxonDao.findByUuid(acherontia);
108
    }
109

    
110
    @After
111
    public void tearDown() {
112
        AuditEventContextHolder.clearContext();
113
    }
114

    
115
    /**
116
     * Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.taxon.TaxonDaoHibernateImpl#TaxonDaoHibernateImpl()}.
117
     */
118
    @Test
119
    @DataSet(value="TaxonDaoHibernateImplTest.xml")
120
    public void testInit() {
121
        logger.warn("testInit()");
122
        assertNotNull("Instance of ITaxonDao expected",taxonDao);
123
        assertNotNull("Instance of IReferenceDao expected",referenceDao);
124
    }
125

    
126
    @Test
127
    @DataSet(value="TaxonDaoHibernateImplTest.xml")
128
    public void updateTaxon() {
129

    
130
        Taxon taxon = (Taxon) taxonDao.findByUuid(acherontiaLachesis);
131

    
132
        long startMillis = System.currentTimeMillis();
133
        for(int indx = 0; indx < BENCHMARK_ROUNDS; indx++){
134
            taxon.setTitleCache("Acherontia lachesis benchmark_" + indx + " Eitschberger, 2003", true);
135
            taxonDao.saveOrUpdate(taxon);
136
            logger.debug("[" + indx + "]" + taxon.getTitleCache());
137
        }
138
        double duration = ((double)(System.currentTimeMillis() - startMillis) ) / BENCHMARK_ROUNDS ;
139
        logger.info("Benchmark result - [update one Taxon] : " + duration + "ms (" + BENCHMARK_ROUNDS +" benchmark rounds )");
140
    }
141

    
142

    
143

    
144

    
145

    
146

    
147

    
148

    
149

    
150

    
151

    
152

    
153

    
154

    
155

    
156

    
157

    
158

    
159

    
160

    
161
}
(1-1/4)