aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2014-11-21 17:19:11 +0100
committerJulien HENRY <julien.henry@sonarsource.com>2014-11-21 17:39:35 +0100
commited320cb526d0f96dddcd0f735895e8c907fc0f8e (patch)
treeb748304641e229456aff340b18f3ae513497093f /sonar-batch
parente667d941dd0f6155982140bdedd0208fd6cf9674 (diff)
downloadsonarqube-ed320cb526d0f96dddcd0f735895e8c907fc0f8e.tar.gz
sonarqube-ed320cb526d0f96dddcd0f735895e8c907fc0f8e.zip
SONAR-5827 Use byte[] instead of String to manipulate file_sources data so that all DBs are happy
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/index/SourcePersister.java5
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/index/SourcePersisterTest.java38
-rw-r--r--sonar-batch/src/test/resources/org/sonar/batch/index/SourcePersisterTest/testPersistNewFileNoScmNoHighlighting-result.xml7
-rw-r--r--sonar-batch/src/test/resources/org/sonar/batch/index/SourcePersisterTest/testPersistNewFileWithScmAndHighlighting-result.xml7
-rw-r--r--sonar-batch/src/test/resources/org/sonar/batch/index/SourcePersisterTest/testPersistUpdateChanged-result.xml5
5 files changed, 35 insertions, 27 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/SourcePersister.java b/sonar-batch/src/main/java/org/sonar/batch/index/SourcePersister.java
index 0ce9d1f7737..3867095ad87 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/index/SourcePersister.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/index/SourcePersister.java
@@ -152,14 +152,15 @@ public class SourcePersister implements ScanPersister {
String newDataHash = newData != null ? DigestUtils.md5Hex(newData) : "0";
Date now = system2.newDate();
if (previous == null) {
- FileSourceDto newFileSource = new FileSourceDto().setProjectUuid(projectTree.getRootProject().getUuid()).setFileUuid(fileUuid).setData(newData).setDataHash(newDataHash)
+ FileSourceDto newFileSource = new FileSourceDto().setProjectUuid(projectTree.getRootProject().getUuid()).setFileUuid(fileUuid).setStringData(newData)
+ .setDataHash(newDataHash)
.setCreatedAt(now)
.setUpdatedAt(now);
mapper.insert(newFileSource);
session.commit();
} else {
if (!newDataHash.equals(previous.getDataHash())) {
- previous.setData(newData).setDataHash(newDataHash).setUpdatedAt(now);
+ previous.setStringData(newData).setDataHash(newDataHash).setUpdatedAt(now);
mapper.update(previous);
session.commit();
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/SourcePersisterTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/SourcePersisterTest.java
index 453363df1ef..5efb6cf5ffc 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/index/SourcePersisterTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/index/SourcePersisterTest.java
@@ -43,11 +43,14 @@ import org.sonar.batch.scan.measure.MeasureCache;
import org.sonar.batch.source.CodeColorizers;
import org.sonar.core.persistence.AbstractDaoTestCase;
import org.sonar.core.source.SnapshotDataTypes;
+import org.sonar.core.source.db.FileSourceDao;
+import org.sonar.core.source.db.FileSourceDto;
import org.sonar.core.source.db.SnapshotSourceDao;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
+import java.util.Date;
import static org.fest.assertions.Assertions.assertThat;
import static org.mockito.Matchers.any;
@@ -121,7 +124,8 @@ public class SourcePersisterTest extends AbstractDaoTestCase {
@Test
public void testPersistUpdateChanged() throws Exception {
setupData("file_sources");
- when(system2.newDate()).thenReturn(DateUtils.parseDateTime("2014-10-29T16:44:02+0100"));
+ Date now = DateUtils.parseDateTime("2014-10-29T16:44:02+0100");
+ when(system2.newDate()).thenReturn(now);
String relativePathSame = "src/changed.java";
java.io.File sameFile = new java.io.File(basedir, relativePathSame);
@@ -132,7 +136,13 @@ public class SourcePersisterTest extends AbstractDaoTestCase {
mockResourceCache(relativePathSame, PROJECT_KEY, "uuidsame");
sourcePersister.persist();
- checkTables("testPersistUpdateChanged", "file_sources");
+
+ FileSourceDto fileSourceDto = new FileSourceDao(getMyBatis()).select("uuidsame");
+ assertThat(fileSourceDto.getCreatedAt()).isEqualTo(DateUtils.parseDateTime("2014-10-10T16:44:02+0200"));
+ assertThat(fileSourceDto.getUpdatedAt()).isEqualTo(now);
+ assertThat(fileSourceDto.getStringData()).isEqualTo(
+ ",,,,changed\r\n,,,,content\r\n");
+ assertThat(fileSourceDto.getDataHash()).isEqualTo("e41cca9c51ff853c748f708f39dfc035");
}
@Test
@@ -153,7 +163,8 @@ public class SourcePersisterTest extends AbstractDaoTestCase {
@Test
public void testPersistNewFileNoScmNoHighlighting() throws Exception {
setupData("file_sources");
- when(system2.newDate()).thenReturn(DateUtils.parseDateTime("2014-10-29T16:44:02+0100"));
+ Date now = DateUtils.parseDateTime("2014-10-29T16:44:02+0100");
+ when(system2.newDate()).thenReturn(now);
String relativePathNew = "src/new.java";
java.io.File newFile = new java.io.File(basedir, relativePathNew);
@@ -164,13 +175,20 @@ public class SourcePersisterTest extends AbstractDaoTestCase {
mockResourceCache(relativePathNew, PROJECT_KEY, "uuidnew");
sourcePersister.persist();
- checkTables("testPersistNewFileNoScmNoHighlighting", "file_sources");
+ FileSourceDto fileSourceDto = new FileSourceDao(getMyBatis()).select("uuidnew");
+ assertThat(fileSourceDto.getCreatedAt()).isEqualTo(now);
+ assertThat(fileSourceDto.getUpdatedAt()).isEqualTo(now);
+ assertThat(fileSourceDto.getStringData()).isEqualTo(
+ ",,,,foo\r\n,,,,bar\r\n,,,,biz\r\n");
+ assertThat(fileSourceDto.getDataHash()).isEqualTo("0c43ed6418d690ee0ffc3e43e6660967");
+
}
@Test
public void testPersistNewFileWithScmAndHighlighting() throws Exception {
setupData("file_sources");
- when(system2.newDate()).thenReturn(DateUtils.parseDateTime("2014-10-29T16:44:02+0100"));
+ Date now = DateUtils.parseDateTime("2014-10-29T16:44:02+0100");
+ when(system2.newDate()).thenReturn(now);
String relativePathNew = "src/new.java";
java.io.File newFile = new java.io.File(basedir, relativePathNew);
@@ -199,7 +217,15 @@ public class SourcePersisterTest extends AbstractDaoTestCase {
.thenReturn(highlighting);
sourcePersister.persist();
- checkTables("testPersistNewFileWithScmAndHighlighting", "file_sources");
+
+ FileSourceDto fileSourceDto = new FileSourceDao(getMyBatis()).select("uuidnew");
+ assertThat(fileSourceDto.getCreatedAt()).isEqualTo(now);
+ assertThat(fileSourceDto.getUpdatedAt()).isEqualTo(now);
+ assertThat(fileSourceDto.getStringData()).isEqualTo(
+ "123,julien,2014-10-11T16:44:02+0100,\"0,3,a\",foo\r\n"
+ + "234,simon,2014-10-12T16:44:02+0100,\"0,1,cd\",bar\r\n"
+ + "345,julien,2014-10-13T16:44:02+0100,\"0,9,c\",biz\r\n");
+ assertThat(fileSourceDto.getDataHash()).isEqualTo("a2aaee165e33957a67331fb9f869e0f1");
}
@Test
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/SourcePersisterTest/testPersistNewFileNoScmNoHighlighting-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/SourcePersisterTest/testPersistNewFileNoScmNoHighlighting-result.xml
deleted file mode 100644
index 782ada21c80..00000000000
--- a/sonar-batch/src/test/resources/org/sonar/batch/index/SourcePersisterTest/testPersistNewFileNoScmNoHighlighting-result.xml
+++ /dev/null
@@ -1,7 +0,0 @@
-<dataset>
- <file_sources id="101" project_uuid="projectUuid" file_uuid="uuidsame" data=",,,,unchanged&#13;&#10;,,,,content&#13;&#10;" data_hash="ee716d4ed9faae16eb9167714442a3bc" created_at="2014-10-10 16:44:02.000" updated_at="2014-10-10 16:44:02.000" />
- <file_sources id="102" project_uuid="projectUuid" file_uuid="uuidnew" data=",,,,foo&#13;&#10;,,,,bar&#13;&#10;,,,,biz&#13;&#10;" data_hash="0c43ed6418d690ee0ffc3e43e6660967" created_at="2014-10-29 16:44:02.000" updated_at="2014-10-29 16:44:02.000" />
-</dataset>
-
-
-
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/SourcePersisterTest/testPersistNewFileWithScmAndHighlighting-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/SourcePersisterTest/testPersistNewFileWithScmAndHighlighting-result.xml
deleted file mode 100644
index 6f3788dfabd..00000000000
--- a/sonar-batch/src/test/resources/org/sonar/batch/index/SourcePersisterTest/testPersistNewFileWithScmAndHighlighting-result.xml
+++ /dev/null
@@ -1,7 +0,0 @@
-<dataset>
- <file_sources id="101" project_uuid="projectUuid" file_uuid="uuidsame" data=",,,,unchanged&#13;&#10;,,,,content&#13;&#10;" data_hash="ee716d4ed9faae16eb9167714442a3bc" created_at="2014-10-10 16:44:02.000" updated_at="2014-10-10 16:44:02.000" />
- <file_sources id="102" project_uuid="projectUuid" file_uuid="uuidnew" data="123,julien,2014-10-11T16:44:02+0100,&#34;0,3,a&#34;,foo&#13;&#10;234,simon,2014-10-12T16:44:02+0100,&#34;0,1,cd&#34;,bar&#13;&#10;345,julien,2014-10-13T16:44:02+0100,&#34;0,9,c&#34;,biz&#13;&#10;" data_hash="a2aaee165e33957a67331fb9f869e0f1" created_at="2014-10-29 16:44:02.000" updated_at="2014-10-29 16:44:02.000" />
-</dataset>
-
-
-
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/SourcePersisterTest/testPersistUpdateChanged-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/SourcePersisterTest/testPersistUpdateChanged-result.xml
deleted file mode 100644
index dfc771b0722..00000000000
--- a/sonar-batch/src/test/resources/org/sonar/batch/index/SourcePersisterTest/testPersistUpdateChanged-result.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<dataset>
-
- <file_sources id="101" project_uuid="projectUuid" file_uuid="uuidsame" data=",,,,changed&#13;&#10;,,,,content&#13;&#10;" data_hash="e41cca9c51ff853c748f708f39dfc035" created_at="2014-10-10 16:44:02.000" updated_at="2014-10-29 16:44:02.000" />
-
-</dataset>