Skip to content

Commit

Permalink
fixes #902
Browse files Browse the repository at this point in the history
1. Fix for #902
2. Updated test log4j2 config
3. Added stress tests
  • Loading branch information
anidotnet committed Feb 16, 2024
1 parent 28750a6 commit 029d5cf
Show file tree
Hide file tree
Showing 22 changed files with 292 additions and 41 deletions.
7 changes: 6 additions & 1 deletion nitrite-jackson-mapper/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<artifactId>log4j-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j2-impl</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
6 changes: 3 additions & 3 deletions nitrite-jackson-mapper/src/test/resources/log4j2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@
~ limitations under the License.
-->

<Configuration status="ERROR" name="nitrite" monitorInterval="5">
<Configuration status="OFF" name="nitrite" monitorInterval="5">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d %p %c{1.} [%t] %m%n"/>
</Console>
</Appenders>
<Loggers>
<Root level="ERROR">
<Root level="OFF">
<AppenderRef ref="Console"/>
</Root>
<Logger name="org.dizitart" level="ERROR" additivity="false">
<Logger name="org.dizitart" level="OFF" additivity="false">
<AppenderRef ref="Console"/>
</Logger>
</Loggers>
Expand Down
7 changes: 6 additions & 1 deletion nitrite-mvstore-adapter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<artifactId>log4j-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j2-impl</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import jakarta.xml.bind.annotation.XmlSchemaType;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.time.StopWatch;
import org.dizitart.no2.Nitrite;
import org.dizitart.no2.collection.Document;
import org.dizitart.no2.collection.DocumentCursor;
Expand All @@ -35,18 +36,18 @@
import org.dizitart.no2.repository.annotations.Id;
import org.dizitart.no2.repository.annotations.Index;
import org.dizitart.no2.repository.annotations.Indices;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.*;
import uk.co.jemos.podam.api.PodamFactory;
import uk.co.jemos.podam.api.PodamFactoryImpl;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicLong;

import static org.dizitart.no2.collection.UpdateOptions.updateOptions;
import static org.dizitart.no2.filters.FluentFilter.where;
import static org.dizitart.no2.integration.TestUtil.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
Expand Down Expand Up @@ -109,6 +110,57 @@ public void stressTest() {
assertEquals(counter, size);
}

@Test
@Ignore
public void testIssue902() {
NitriteCollection nitriteCollection = db.getCollection("testIssue902");
nitriteCollection.createIndex(IndexOptions.indexOptions(IndexType.NON_UNIQUE), "name");
nitriteCollection.createIndex(IndexOptions.indexOptions(IndexType.NON_UNIQUE), "age");
nitriteCollection.createIndex(IndexOptions.indexOptions(IndexType.NON_UNIQUE), "address");
nitriteCollection.createIndex(IndexOptions.indexOptions(IndexType.NON_UNIQUE), "email");
nitriteCollection.createIndex(IndexOptions.indexOptions(IndexType.NON_UNIQUE), "phone");
nitriteCollection.createIndex(IndexOptions.indexOptions(IndexType.NON_UNIQUE), "dateOfBirth");
nitriteCollection.createIndex(IndexOptions.indexOptions(IndexType.NON_UNIQUE), "company");
nitriteCollection.createIndex(IndexOptions.indexOptions(IndexType.NON_UNIQUE), "balance");
nitriteCollection.createIndex(IndexOptions.indexOptions(IndexType.NON_UNIQUE), "isActive");
nitriteCollection.createIndex(IndexOptions.indexOptions(IndexType.UNIQUE), "guid");
nitriteCollection.createIndex(IndexOptions.indexOptions(IndexType.NON_UNIQUE), "index");

for (int i = 0; i < 10; i++) {
StopWatch stopWatch = new StopWatch();
stopWatch.start();
for (int j = 0; j < 30000; j++) {
Document document = Document.createDocument();
document.put("name", "name" + j);
document.put("age", j);
document.put("address", "address" + j);
document.put("email", "email" + j);
document.put("phone", "phone" + j);
document.put("dateOfBirth", "dateOfBirth" + j);
document.put("company", "company" + j);
document.put("balance", j);
document.put("isActive", true);
document.put("guid", UUID.randomUUID().toString());
document.put("index", j);
nitriteCollection.insert(document);
}
stopWatch.stop();
log.error("Time taken to insert 30000 records: " + stopWatch.getTime());
}

if (db.hasUnsavedChanges()) {
db.commit();
}

Document updatedDocument = Document.createDocument("unrelatedField", "unrelatedValue");
StopWatch stopWatch = new StopWatch();
stopWatch.start();
nitriteCollection.update(where("balance").eq(200000), updatedDocument, updateOptions(false));
stopWatch.stop();

log.error("Time taken to update 1 record: " + stopWatch.getTime());
}

@Test
public void testIssue41() {
collection.createIndex(IndexOptions.indexOptions(IndexType.NON_UNIQUE), "number");
Expand Down
6 changes: 3 additions & 3 deletions nitrite-mvstore-adapter/src/test/resources/log4j2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@
~ limitations under the License.
-->

<Configuration status="ERROR" name="nitrite" monitorInterval="5">
<Configuration status="OFF" name="nitrite" monitorInterval="5">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d %p %c{1.} [%t] %m%n"/>
</Console>
</Appenders>
<Loggers>
<Root level="ERROR">
<Root level="OFF">
<AppenderRef ref="Console"/>
</Root>
<Logger name="org.dizitart" level="ERROR" additivity="false">
<Logger name="org.dizitart" level="OFF" additivity="false">
<AppenderRef ref="Console"/>
</Logger>
</Loggers>
Expand Down
7 changes: 6 additions & 1 deletion nitrite-rocksdb-adapter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,12 @@
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<artifactId>log4j-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j2-impl</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import jakarta.xml.bind.annotation.XmlSchemaType;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.time.StopWatch;
import org.dizitart.no2.Nitrite;
import org.dizitart.no2.collection.Document;
import org.dizitart.no2.collection.DocumentCursor;
Expand All @@ -35,18 +36,18 @@
import org.dizitart.no2.repository.annotations.Id;
import org.dizitart.no2.repository.annotations.Index;
import org.dizitart.no2.repository.annotations.Indices;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.*;
import uk.co.jemos.podam.api.PodamFactory;
import uk.co.jemos.podam.api.PodamFactoryImpl;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicLong;

import static org.dizitart.no2.collection.UpdateOptions.updateOptions;
import static org.dizitart.no2.filters.FluentFilter.where;
import static org.dizitart.no2.integration.TestUtil.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
Expand Down Expand Up @@ -108,6 +109,57 @@ public void stressTest() {
assertEquals(counter, size);
}

@Test
@Ignore
public void testIssue902() {
NitriteCollection nitriteCollection = db.getCollection("testIssue902");
nitriteCollection.createIndex(IndexOptions.indexOptions(IndexType.NON_UNIQUE), "name");
nitriteCollection.createIndex(IndexOptions.indexOptions(IndexType.NON_UNIQUE), "age");
nitriteCollection.createIndex(IndexOptions.indexOptions(IndexType.NON_UNIQUE), "address");
nitriteCollection.createIndex(IndexOptions.indexOptions(IndexType.NON_UNIQUE), "email");
nitriteCollection.createIndex(IndexOptions.indexOptions(IndexType.NON_UNIQUE), "phone");
nitriteCollection.createIndex(IndexOptions.indexOptions(IndexType.NON_UNIQUE), "dateOfBirth");
nitriteCollection.createIndex(IndexOptions.indexOptions(IndexType.NON_UNIQUE), "company");
nitriteCollection.createIndex(IndexOptions.indexOptions(IndexType.NON_UNIQUE), "balance");
nitriteCollection.createIndex(IndexOptions.indexOptions(IndexType.NON_UNIQUE), "isActive");
nitriteCollection.createIndex(IndexOptions.indexOptions(IndexType.UNIQUE), "guid");
nitriteCollection.createIndex(IndexOptions.indexOptions(IndexType.NON_UNIQUE), "index");

for (int i = 0; i < 10; i++) {
StopWatch stopWatch = new StopWatch();
stopWatch.start();
for (int j = 0; j < 3000; j++) {
Document document = Document.createDocument();
document.put("name", "name" + j);
document.put("age", j);
document.put("address", "address" + j);
document.put("email", "email" + j);
document.put("phone", "phone" + j);
document.put("dateOfBirth", "dateOfBirth" + j);
document.put("company", "company" + j);
document.put("balance", j);
document.put("isActive", true);
document.put("guid", UUID.randomUUID().toString());
document.put("index", j);
nitriteCollection.insert(document);
}
stopWatch.stop();
log.error("Time taken to insert 30000 records: " + stopWatch.getTime());
}

if (db.hasUnsavedChanges()) {
db.commit();
}

Document updatedDocument = Document.createDocument("unrelatedField", "unrelatedValue");
StopWatch stopWatch = new StopWatch();
stopWatch.start();
nitriteCollection.update(where("balance").eq(200000), updatedDocument, updateOptions(false));
stopWatch.stop();

log.error("Time taken to update 1 record: " + stopWatch.getTime());
}

@Test
public void testIssue41() {
collection.createIndex(IndexOptions.indexOptions(IndexType.NON_UNIQUE), "number");
Expand Down
6 changes: 3 additions & 3 deletions nitrite-rocksdb-adapter/src/test/resources/log4j2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@
~ limitations under the License.
-->

<Configuration status="ERROR" name="nitrite" monitorInterval="5">
<Configuration status="OFF" name="nitrite" monitorInterval="5">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d %p %c{1.} [%t] %m%n"/>
</Console>
</Appenders>
<Loggers>
<Root level="ERROR">
<Root level="OFF">
<AppenderRef ref="Console"/>
</Root>
<Logger name="org.dizitart" level="ERROR" additivity="false">
<Logger name="org.dizitart" level="OFF" additivity="false">
<AppenderRef ref="Console"/>
</Logger>
</Loggers>
Expand Down
15 changes: 15 additions & 0 deletions nitrite-spatial/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,21 @@
<artifactId>nitrite-mvstore-adapter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j2-impl</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
31 changes: 31 additions & 0 deletions nitrite-spatial/src/test/resources/log4j2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!--
~ Copyright (c) 2017-2020. Nitrite author or authors.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<Configuration status="OFF" name="nitrite" monitorInterval="5">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d %p %c{1.} [%t] %m%n"/>
</Console>
</Appenders>
<Loggers>
<Root level="OFF">
<AppenderRef ref="Console"/>
</Root>
<Logger name="org.dizitart" level="OFF" additivity="false">
<AppenderRef ref="Console"/>
</Logger>
</Loggers>
</Configuration>
15 changes: 15 additions & 0 deletions nitrite-support/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,21 @@
<artifactId>snakeyaml</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j2-impl</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
6 changes: 3 additions & 3 deletions nitrite-support/src/test/resources/log4j2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@
~ limitations under the License.
-->

<Configuration status="ERROR" name="nitrite" monitorInterval="5">
<Configuration status="OFF" name="nitrite" monitorInterval="5">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d %p %c{1.} [%t] %m%n"/>
</Console>
</Appenders>
<Loggers>
<Root level="ERROR">
<Root level="OFF">
<AppenderRef ref="Console"/>
</Root>
<Logger name="org.dizitart" level="ERROR" additivity="false">
<Logger name="org.dizitart" level="OFF" additivity="false">
<AppenderRef ref="Console"/>
</Logger>
</Loggers>
Expand Down
7 changes: 6 additions & 1 deletion nitrite/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,12 @@
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<artifactId>log4j-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j2-impl</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Loading

0 comments on commit 029d5cf

Please sign in to comment.