Skip to content

Commit 6712506

Browse files
committed
fix for issue #29
1 parent 8e75ed1 commit 6712506

File tree

4 files changed

+175
-2
lines changed

4 files changed

+175
-2
lines changed

gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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/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) {
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)