Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in bulk test #182

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
import org.ektorp.impl.StdObjectMapperFactory;
import org.ektorp.impl.StreamedCouchDbConnector;
import org.ektorp.support.CouchDbDocument;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -50,10 +47,9 @@
at org.ektorp.http.StdHttpClient.executeRequest(StdHttpClient.java:96)
... 5 more
*/
@Ignore
public class BulkTest {
public class BulkIT {

private final static Logger LOG = LoggerFactory.getLogger(StdCouchDbInstance.class);
private final static Logger LOG = LoggerFactory.getLogger(BulkIT.class);

private HttpClient httpClient;

Expand All @@ -67,7 +63,7 @@ public class BulkTest {

private boolean createDatabaseIfNeeded = true;

private boolean deleteDatabaseIfNeeded = false;
private boolean deleteDatabaseIfNeeded = true;

@Before
public void setUp() {
Expand Down Expand Up @@ -165,7 +161,7 @@ public void shouldUpdateInBulkWithManyElementsWithStreamedCouchDbConnector() thr
}

public void doUpdateInBulkWithOneElement(CouchDbConnector db) throws Exception {
final int iterationsCount = 100;
final int iterationsCount = 10;

// create document "myid"
try {
Expand All @@ -192,8 +188,8 @@ public void doUpdateInBulkWithOneElement(CouchDbConnector db) throws Exception {


public void doUpdateInBulkWithManyElements(CouchDbConnector db) {
final int iterationsCount = 20;
final int elementsCount = 200;
final int iterationsCount = 10;
final int elementsCount = 20;

final List<String> allDocIds = new ArrayList<String>();

Expand Down Expand Up @@ -240,11 +236,12 @@ public void doUpdateInBulkWithManyElements(CouchDbConnector db) {

List<TestDocumentBean> docList = db.queryView(q, TestDocumentBean.class);
for (TestDocumentBean b : docList) {
Assert.assertNotNull(b.firstName);
Assert.assertNotNull(b.getLastName());
Assert.assertNotNull(b.dateOfBirth);
// check version is as expected
if (b.version != i - 1) {
throw new IllegalStateException("Bean state is not as expected : " + b);
}
b.version = i;
Assert.assertEquals("Bean state is not as expected", i - 1, b.getVersion());
b.setVersion(i);
}

long bulkOpStart = System.currentTimeMillis();
Expand All @@ -258,7 +255,7 @@ public void doUpdateInBulkWithManyElements(CouchDbConnector db) {
List<TestDocumentBean> docList = db.queryView(q, TestDocumentBean.class);
for (TestDocumentBean b : docList) {
// check version is as expected
if (b.version != iterationsCount) {
if (b.getVersion() != iterationsCount) {
throw new IllegalStateException("Bean state is not as expected : " + b);
}
}
Expand All @@ -268,7 +265,7 @@ public void doUpdateInBulkWithManyElements(CouchDbConnector db) {
}

public void doUpdateInBulkWithOneSmallInputStream(CouchDbConnector db) throws Exception {
final int iterationsCount = 100;
final int iterationsCount = 10;

// create or update the document, with initial "i" value of 0
final String id = "myid";
Expand Down Expand Up @@ -317,7 +314,7 @@ public static class TestDocumentBean extends CouchDbDocument {
private String lastName;
private String firstName;
private Long dateOfBirth;
private int version;
private int version = -1;

public TestDocumentBean() {

Expand All @@ -329,6 +326,38 @@ public TestDocumentBean(String lastName, String firstName, Long dateOfBirth, int
this.dateOfBirth = dateOfBirth;
this.version = version;
}

public int getVersion() {
return version;
}

public void setVersion(int version) {
this.version = version;
}

public String getFirstName() {
return firstName;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
}

public Long getDateOfBirth() {
return dateOfBirth;
}

public void setDateOfBirth(Long dateOfBirth) {
this.dateOfBirth = dateOfBirth;
}

public String getLastName() {
return lastName;
}

public void setLastName(String lastName) {
this.lastName = lastName;
}
}

}
Expand Down
95 changes: 95 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@

<findbugs.skip>false</findbugs.skip>
<findbugs.includeTests>false</findbugs.includeTests>

<skipITs>true</skipITs>
<sonar.core.codeCoveragePlugin>jacoco</sonar.core.codeCoveragePlugin>
<sonar.jacoco.itReportPath>${project.basedir}/../target/jacoco-it.exec</sonar.jacoco.itReportPath>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -149,6 +153,25 @@
<artifactId>findbugs-maven-plugin</artifactId>
<version>2.5.3</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.16</version>
<configuration>
<argLine>${jacoco.agent.argLine}</argLine>
<includes>
<include>**/*IT.java</include>
</includes>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
<plugins>
Expand Down Expand Up @@ -210,6 +233,23 @@
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<skipITs>${skipITs}</skipITs>
<!-- to fool Sonar to show test success for both unit and integration tests together -->
<reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
<argLine>${jacoco.agent.argLine}</argLine>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
Expand Down Expand Up @@ -293,5 +333,60 @@
<sonarVersion>2.1</sonarVersion>
</properties>
</profile>


<profile>
<id>sonar</id>
<!-- Enable coverage computation via JaCoCo for Sonar's needs -->

<properties>
<skipITs>false</skipITs>
</properties>

<build>
<plugins>
<!--
Compute integration test coverage for Sonar
Note: REQUIRES MAVEN 3 - throws InstantiationException: java.util.List otherwise
Beware: Sonar doesn't run the verify phase; you should always 'mvn clean install' before running sonar
-->
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<configuration>
<propertyName>jacoco.agent.argLine</propertyName>
<!-- default: argLine -->
<includes>
<include>org/ektorp/**</include>
</includes>
<destFile>${project.build.directory}/jacoco-integration.exec</destFile>
<!-- agent -->
<dataFile>${project.build.directory}/jacoco-integration.exec</dataFile>
<!-- report -->
</configuration>
<executions>
<execution>
<id>agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<!--
Generate coverage report html in target/site/jacoco/ from target/jacoco.exec
Exec.: mvn verify site
-->
<id>report</id>
<phase>site</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>

</profiles>
</project>