|
| 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