Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ deploy:

env:
global:
- NITRITE_VERSION=2.0.0
- NITRITE_VERSION=2.0.1
- PGP_KEY_FILE=~/secring.gpg
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
org.gradle.jvmargs=-Xmx1024m

# artifact version
nitriteVersion=2.0.0
nitriteVersion=2.0.1

# nitrite dependency
asciidoctorVersion=1.5.4
Expand Down Expand Up @@ -50,6 +50,7 @@ nexusStagingPlugin=0.8.0
objenesisVersion=2.6
okhttpVersion=3.6.0
orientdbVersion=2.2.10
podamVersion=7.0.5.RELEASE
propDepsPluginVersion=0.0.7
shadowPluginVersion=1.2.4
slf4jVersion=1.7.21
Expand Down
2 changes: 1 addition & 1 deletion nitrite/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ dependencies {
testCompile "joda-time:joda-time:$jodaTimeVersion"
testCompile "com.squareup.okhttp3:mockwebserver:$okhttpVersion"
testCompile "org.meanbean:meanbean:$meanbeanVersion"

testCompile "uk.co.jemos.podam:podam:$podamVersion"
}

gradle.buildFinished { BuildResult result ->
Expand Down
3 changes: 1 addition & 2 deletions nitrite/src/main/java/org/dizitart/no2/Document.java
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ public void remove() {
}

private boolean validId(Object value) {
return value instanceof Long
&& Math.floor(Math.log10((long) value) + 1) == 19;
return value instanceof Long;
}
}
4 changes: 3 additions & 1 deletion nitrite/src/main/java/org/dizitart/no2/NitriteId.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.dizitart.no2.exceptions.InvalidIdException;

import java.io.Serializable;
import java.util.concurrent.atomic.AtomicLong;

import static org.dizitart.no2.Constants.ID_PREFIX;
import static org.dizitart.no2.Constants.ID_SUFFIX;
Expand All @@ -43,11 +44,12 @@
@EqualsAndHashCode
public final class NitriteId implements Comparable<NitriteId>, Serializable {
private static final long serialVersionUID = 1477462375L;
private static final AtomicLong counter = new AtomicLong(System.nanoTime());

private Long idValue;

private NitriteId() {
idValue = new ObjectId().toLong();
idValue = counter.getAndIncrement();
}

private NitriteId(Long value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public <T> Document asDocumentInternal(T object) {
JsonNode node = objectMapper.convertValue(object, JsonNode.class);
return loadDocument(node);
} catch (IllegalArgumentException iae) {
log.error("Error while converting object to document ", iae);
if (iae.getCause() instanceof JsonMappingException) {
JsonMappingException jme = (JsonMappingException) iae.getCause();
if (jme.getCause() instanceof StackOverflowError) {
Expand All @@ -73,12 +74,12 @@ public <T> T asObjectInternal(Document document, Class<T> type) {
try {
return getObjectMapper().convertValue(document, type);
} catch (IllegalArgumentException iae) {
log.error("Error while converting document to object ", iae);
if (iae.getCause() instanceof JsonMappingException) {
JsonMappingException jme = (JsonMappingException) iae.getCause();
if (jme.getMessage().contains("Can not construct instance")) {
throw new ObjectMappingException(errorMessage(
"no default parameter-less constructor found for "
+ type.getName(), OME_NO_DEFAULT_CTOR));
jme.getMessage(), OME_NO_DEFAULT_CTOR));
}
}
throw iae;
Expand Down Expand Up @@ -125,6 +126,7 @@ public Document parse(String json) {
JsonNode node = objectMapper.readValue(json, JsonNode.class);
return loadDocument(node);
} catch (IOException e) {
log.error("Error while parsing json", e);
throw new ObjectMappingException(errorMessage("failed to parse json " + json,
OME_PARSE_JSON_FAILED));
}
Expand All @@ -137,6 +139,7 @@ public String toJson(Object object) {
getObjectMapper().writeValue(stringWriter, object);
return stringWriter.toString();
} catch (IOException e) {
log.error("Error while serializing object to json", e);
throw new ObjectMappingException(JSON_SERIALIZATION_FAILED);
}
}
Expand Down
170 changes: 170 additions & 0 deletions nitrite/src/test/java/org/dizitart/no2/NitriteStressTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
package org.dizitart.no2;

import org.dizitart.no2.objects.Id;
import org.dizitart.no2.objects.ObjectRepository;
import org.junit.Test;
import uk.co.jemos.podam.api.PodamFactory;
import uk.co.jemos.podam.api.PodamFactoryImpl;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlSchemaType;
import java.util.ArrayList;
import java.util.List;

/**
* @author Anindya Chatterjee
*/
public class NitriteStressTest {
private PodamFactory podamFactory = new PodamFactoryImpl();

private static final int TEST_SET_COUNT = 15000;
private Nitrite database;
private ObjectRepository<TestDto> testRepository;

@Test
public void stressTest() {
database = Nitrite.builder().openOrCreate();
testRepository = database.getRepository(TestDto.class);
testRepository.createIndex("lastName", IndexOptions.indexOptions(IndexType.Fulltext));
testRepository.createIndex("birthDate", IndexOptions.indexOptions(IndexType.NonUnique));

int counter = 0;
try {
for (TestDto testDto : createTestSet()) {
testRepository.insert(testDto);
counter++;
}
} catch (Throwable t) {
System.err.println("Crashed after " + counter + " records");
throw t;
}
}

private List<TestDto> createTestSet() {
List<TestDto> testData = new ArrayList<>();
for (int i = 0; i < TEST_SET_COUNT; i++) {
TestDto testRecords = podamFactory.manufacturePojo(TestDto.class);
testData.add(testRecords);
}
return testData;
}

public class TestDto {

@XmlElement(
name = "StudentNumber",
required = true
)
@Id
protected String studentNumber;

@XmlElement(
name = "LastName",
required = true
)
protected String lastName;

@XmlElement(
name = "Prefixes"
)
protected String prefixes;

@XmlElement(
name = "Initials",
required = true
)
protected String initials;

@XmlElement(
name = "FirstNames"
)
protected String firstNames;
@XmlElement(
name = "Nickname"
)
protected String nickName;

@XmlElement(
name = "BirthDate",
required = true
)
@XmlSchemaType(
name = "date"
)
protected String birthDate;


public TestDto() {
}


public String getStudentNumber() {
return this.studentNumber;
}


public void setStudentNumber(String value) {
this.studentNumber = value;
}


public String getLastName() {
return this.lastName;
}


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


public String getPrefixes() {
return this.prefixes;
}


public void setPrefixes(String value) {
this.prefixes = value;
}


public String getInitials() {
return this.initials;
}


public void setInitials(String value) {
this.initials = value;
}


public String getFirstNames() {
return this.firstNames;
}


public void setFirstNames(String value) {
this.firstNames = value;
}


public String getNickName() {
return this.nickName;
}


public void setNickName(String value) {
this.nickName = value;
}


public String getBirthDate() {
return this.birthDate;
}


public void setBirthDate(String value) {
this.birthDate = value;
}
}
}