Skip to content

Commit d2124ae

Browse files
authored
Merge pull request #30 from dizitart/master
2.0.1 release
2 parents 3082c17 + accc50d commit d2124ae

File tree

7 files changed

+183
-8
lines changed

7 files changed

+183
-8
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,5 @@ deploy:
4242

4343
env:
4444
global:
45-
- NITRITE_VERSION=2.0.0
45+
- NITRITE_VERSION=2.0.1
4646
- PGP_KEY_FILE=~/secring.gpg

gradle.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
org.gradle.jvmargs=-Xmx1024m
2323

2424
# artifact version
25-
nitriteVersion=2.0.0
25+
nitriteVersion=2.0.1
2626

2727
# nitrite dependency
2828
asciidoctorVersion=1.5.4
@@ -50,6 +50,7 @@ nexusStagingPlugin=0.8.0
5050
objenesisVersion=2.6
5151
okhttpVersion=3.6.0
5252
orientdbVersion=2.2.10
53+
podamVersion=7.0.5.RELEASE
5354
propDepsPluginVersion=0.0.7
5455
shadowPluginVersion=1.2.4
5556
slf4jVersion=1.7.21

nitrite/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ dependencies {
4949
testCompile "joda-time:joda-time:$jodaTimeVersion"
5050
testCompile "com.squareup.okhttp3:mockwebserver:$okhttpVersion"
5151
testCompile "org.meanbean:meanbean:$meanbeanVersion"
52-
52+
testCompile "uk.co.jemos.podam:podam:$podamVersion"
5353
}
5454

5555
gradle.buildFinished { BuildResult result ->

nitrite/src/main/java/org/dizitart/no2/Document.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,6 @@ public void remove() {
208208
}
209209

210210
private boolean validId(Object value) {
211-
return value instanceof Long
212-
&& Math.floor(Math.log10((long) value) + 1) == 19;
211+
return value instanceof Long;
213212
}
214213
}

nitrite/src/main/java/org/dizitart/no2/NitriteId.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.dizitart.no2.exceptions.InvalidIdException;
2121

2222
import java.io.Serializable;
23+
import java.util.concurrent.atomic.AtomicLong;
2324

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

4749
private Long idValue;
4850

4951
private NitriteId() {
50-
idValue = new ObjectId().toLong();
52+
idValue = counter.getAndIncrement();
5153
}
5254

5355
private NitriteId(Long value) {

nitrite/src/main/java/org/dizitart/no2/mapper/JacksonMapper.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public <T> Document asDocumentInternal(T object) {
5757
JsonNode node = objectMapper.convertValue(object, JsonNode.class);
5858
return loadDocument(node);
5959
} catch (IllegalArgumentException iae) {
60+
log.error("Error while converting object to document ", iae);
6061
if (iae.getCause() instanceof JsonMappingException) {
6162
JsonMappingException jme = (JsonMappingException) iae.getCause();
6263
if (jme.getCause() instanceof StackOverflowError) {
@@ -73,12 +74,12 @@ public <T> T asObjectInternal(Document document, Class<T> type) {
7374
try {
7475
return getObjectMapper().convertValue(document, type);
7576
} catch (IllegalArgumentException iae) {
77+
log.error("Error while converting document to object ", iae);
7678
if (iae.getCause() instanceof JsonMappingException) {
7779
JsonMappingException jme = (JsonMappingException) iae.getCause();
7880
if (jme.getMessage().contains("Can not construct instance")) {
7981
throw new ObjectMappingException(errorMessage(
80-
"no default parameter-less constructor found for "
81-
+ type.getName(), OME_NO_DEFAULT_CTOR));
82+
jme.getMessage(), OME_NO_DEFAULT_CTOR));
8283
}
8384
}
8485
throw iae;
@@ -125,6 +126,7 @@ public Document parse(String json) {
125126
JsonNode node = objectMapper.readValue(json, JsonNode.class);
126127
return loadDocument(node);
127128
} catch (IOException e) {
129+
log.error("Error while parsing json", e);
128130
throw new ObjectMappingException(errorMessage("failed to parse json " + json,
129131
OME_PARSE_JSON_FAILED));
130132
}
@@ -137,6 +139,7 @@ public String toJson(Object object) {
137139
getObjectMapper().writeValue(stringWriter, object);
138140
return stringWriter.toString();
139141
} catch (IOException e) {
142+
log.error("Error while serializing object to json", e);
140143
throw new ObjectMappingException(JSON_SERIALIZATION_FAILED);
141144
}
142145
}
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
package org.dizitart.no2;
2+
3+
import org.dizitart.no2.objects.Id;
4+
import org.dizitart.no2.objects.ObjectRepository;
5+
import org.junit.Test;
6+
import uk.co.jemos.podam.api.PodamFactory;
7+
import uk.co.jemos.podam.api.PodamFactoryImpl;
8+
9+
import javax.xml.bind.annotation.XmlElement;
10+
import javax.xml.bind.annotation.XmlSchemaType;
11+
import java.util.ArrayList;
12+
import java.util.List;
13+
14+
/**
15+
* @author Anindya Chatterjee
16+
*/
17+
public class NitriteStressTest {
18+
private PodamFactory podamFactory = new PodamFactoryImpl();
19+
20+
private static final int TEST_SET_COUNT = 15000;
21+
private Nitrite database;
22+
private ObjectRepository<TestDto> testRepository;
23+
24+
@Test
25+
public void stressTest() {
26+
database = Nitrite.builder().openOrCreate();
27+
testRepository = database.getRepository(TestDto.class);
28+
testRepository.createIndex("lastName", IndexOptions.indexOptions(IndexType.Fulltext));
29+
testRepository.createIndex("birthDate", IndexOptions.indexOptions(IndexType.NonUnique));
30+
31+
int counter = 0;
32+
try {
33+
for (TestDto testDto : createTestSet()) {
34+
testRepository.insert(testDto);
35+
counter++;
36+
}
37+
} catch (Throwable t) {
38+
System.err.println("Crashed after " + counter + " records");
39+
throw t;
40+
}
41+
}
42+
43+
private List<TestDto> createTestSet() {
44+
List<TestDto> testData = new ArrayList<>();
45+
for (int i = 0; i < TEST_SET_COUNT; i++) {
46+
TestDto testRecords = podamFactory.manufacturePojo(TestDto.class);
47+
testData.add(testRecords);
48+
}
49+
return testData;
50+
}
51+
52+
public class TestDto {
53+
54+
@XmlElement(
55+
name = "StudentNumber",
56+
required = true
57+
)
58+
@Id
59+
protected String studentNumber;
60+
61+
@XmlElement(
62+
name = "LastName",
63+
required = true
64+
)
65+
protected String lastName;
66+
67+
@XmlElement(
68+
name = "Prefixes"
69+
)
70+
protected String prefixes;
71+
72+
@XmlElement(
73+
name = "Initials",
74+
required = true
75+
)
76+
protected String initials;
77+
78+
@XmlElement(
79+
name = "FirstNames"
80+
)
81+
protected String firstNames;
82+
@XmlElement(
83+
name = "Nickname"
84+
)
85+
protected String nickName;
86+
87+
@XmlElement(
88+
name = "BirthDate",
89+
required = true
90+
)
91+
@XmlSchemaType(
92+
name = "date"
93+
)
94+
protected String birthDate;
95+
96+
97+
public TestDto() {
98+
}
99+
100+
101+
public String getStudentNumber() {
102+
return this.studentNumber;
103+
}
104+
105+
106+
public void setStudentNumber(String value) {
107+
this.studentNumber = value;
108+
}
109+
110+
111+
public String getLastName() {
112+
return this.lastName;
113+
}
114+
115+
116+
public void setLastName(String value) {
117+
this.lastName = value;
118+
}
119+
120+
121+
public String getPrefixes() {
122+
return this.prefixes;
123+
}
124+
125+
126+
public void setPrefixes(String value) {
127+
this.prefixes = value;
128+
}
129+
130+
131+
public String getInitials() {
132+
return this.initials;
133+
}
134+
135+
136+
public void setInitials(String value) {
137+
this.initials = value;
138+
}
139+
140+
141+
public String getFirstNames() {
142+
return this.firstNames;
143+
}
144+
145+
146+
public void setFirstNames(String value) {
147+
this.firstNames = value;
148+
}
149+
150+
151+
public String getNickName() {
152+
return this.nickName;
153+
}
154+
155+
156+
public void setNickName(String value) {
157+
this.nickName = value;
158+
}
159+
160+
161+
public String getBirthDate() {
162+
return this.birthDate;
163+
}
164+
165+
166+
public void setBirthDate(String value) {
167+
this.birthDate = value;
168+
}
169+
}
170+
}

0 commit comments

Comments
 (0)