diff options
author | simonbrandhof <simon.brandhof@gmail.com> | 2011-11-01 07:58:20 +0100 |
---|---|---|
committer | simonbrandhof <simon.brandhof@gmail.com> | 2011-11-01 08:02:22 +0100 |
commit | 3d544314e585b7c65bc6156f7b7f5748012d50ad (patch) | |
tree | 554fb661f49d6a604ffac3dab425781746430836 /sonar-core/src/test | |
parent | 03d3eaac31c3bec1b80e2f7163f84857a59d75ea (diff) | |
download | sonarqube-3d544314e585b7c65bc6156f7b7f5748012d50ad.tar.gz sonarqube-3d544314e585b7c65bc6156f7b7f5748012d50ad.zip |
Improve insertion of rows in DUPLICATIONS_INDEX: use BATCH mode
Diffstat (limited to 'sonar-core/src/test')
-rw-r--r-- | sonar-core/src/test/java/org/sonar/persistence/dao/DuplicationDaoTest.java | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/sonar-core/src/test/java/org/sonar/persistence/dao/DuplicationDaoTest.java b/sonar-core/src/test/java/org/sonar/persistence/dao/DuplicationDaoTest.java new file mode 100644 index 00000000000..6beea0d4742 --- /dev/null +++ b/sonar-core/src/test/java/org/sonar/persistence/dao/DuplicationDaoTest.java @@ -0,0 +1,75 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2011 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * Sonar 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.persistence.dao; + +import com.google.common.collect.Lists; +import org.dbunit.DataSourceDatabaseTester; +import org.dbunit.IDatabaseTester; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.sonar.persistence.InMemoryDatabase; +import org.sonar.persistence.MyBatis; +import org.sonar.persistence.model.DuplicationUnit; + +import java.util.List; + +import static org.hamcrest.CoreMatchers.nullValue; +import static org.junit.Assert.assertThat; + +public class DuplicationDaoTest { + protected static IDatabaseTester databaseTester; + private static InMemoryDatabase database; + private static DuplicationDao dao; + + @BeforeClass + public static void startDatabase() throws Exception { + database = new InMemoryDatabase(); + MyBatis myBatis = new MyBatis(database); + + database.start(); + myBatis.start(); + + dao = new DuplicationDao(myBatis); + databaseTester = new DataSourceDatabaseTester(database.getDataSource()); + } + + @AfterClass + public static void stopDatabase() throws Exception { + if (databaseTester != null) { + databaseTester.onTearDown(); + } + database.stop(); + } + + @Test + public void testBatchInsert() { + List<DuplicationUnit> duplications = Lists.newArrayList(); + for (int i = 0; i < 50; i++) { + duplications.add(new DuplicationUnit(i, i, "hash", 2, 30, 40)); + } + dao.insert(duplications); + + for (DuplicationUnit duplication : duplications) { + // batch insert : faster but generated ids are not returned + assertThat(duplication.getId(), nullValue()); + } + } +} |