Skip to content

Commit

Permalink
[#9610] Improvements to spring-data-mongodb-reactive
Browse files Browse the repository at this point in the history
  • Loading branch information
jaehong-kim committed Jan 9, 2023
1 parent 44466a8 commit 0a049cc
Show file tree
Hide file tree
Showing 32 changed files with 734 additions and 257 deletions.
6 changes: 6 additions & 0 deletions agent-testweb/bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<apache.dubbo.version>2.7.2</apache.dubbo.version>
<ehcache.version>2.10.6</ehcache.version>
<undertow.version>2.2.17.Final</undertow.version>
<j2html.version>1.6.0</j2html.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -68,6 +69,11 @@
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.4.4</version>
</dependency>
<dependency>
<groupId>com.j2html</groupId>
<artifactId>j2html</artifactId>
<version>${j2html.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
36 changes: 18 additions & 18 deletions agent-testweb/mongodb-plugin-testweb/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,39 @@
<pinpoint.agent.jvmargument>
${pinpoint.agent.default.jvmargument}
</pinpoint.agent.jvmargument>
<spring.boot.version>2.3.12.RELEASE</spring.boot.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring.boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<artifactId>spring-boot-autoconfigure</artifactId>
<version>${spring.boot.version}</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.mongodb/mongodb-driver -->
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver</artifactId>
<version>3.12.11</version>
</dependency>

<dependency>
<groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.mongo</artifactId>
<version>${embed.mongo}</version>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-sync</artifactId>
<version>4.5.0</version>
<groupId>org.testcontainers</groupId>
<artifactId>mongodb</artifactId>
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
import com.mongodb.client.model.Sorts;
import com.mongodb.client.model.UpdateOptions;
import com.mongodb.client.result.DeleteResult;
import com.mongodb.client.result.InsertManyResult;
import com.mongodb.client.result.InsertOneResult;
import com.mongodb.client.result.UpdateResult;
import org.bson.BsonArray;
import org.bson.BsonBinary;
Expand Down Expand Up @@ -87,16 +85,12 @@ public class MongoPluginController {
private static final String DATABASE_NAME_2 = "myMongoDb2";
private static final String COLLECTION_NAME = "customers";

private final MongoServer mongoServer;
private MongoClient mongoClient;

public MongoPluginController(MongoServer mongoServer) {
this.mongoServer = Objects.requireNonNull(mongoServer, "mongoServer");
}

@PostConstruct
public void start() {
this.mongoClient = MongoClients.create(mongoServer.getUri());
final String connectionString = MongoServer.getUri();
this.mongoClient = MongoClients.create(connectionString);
}

@PreDestroy
Expand All @@ -110,8 +104,8 @@ public void shutdown() {
public String insert() {
MongoCollection<Document> collection = getDatabase(DATABASE_NAME).getCollection(COLLECTION_NAME);
Document doc = new Document("name", "pinpoint").append("company", "Naver");
InsertOneResult result = collection.insertOne(doc);
return "Insert=" + result;
collection.insertOne(doc);
return "Insert";
}

@RequestMapping(value = "/mongodb/insertMany")
Expand All @@ -127,8 +121,8 @@ public String insertMany() {
documentList.add(new Document("name", "manymanay" + i).append("company", "ManyCompany"));
}

InsertManyResult result = collection.insertMany(documentList);
return "Insert=" + result;
collection.insertMany(documentList);
return "InsertMany";
}

@RequestMapping(value = "/mongodb/insertComplexBson")
Expand Down Expand Up @@ -165,9 +159,9 @@ public String insertComplex() {
.append("dbPointer", new BsonDbPointer("db.coll", new ObjectId()))
.append("null", new BsonNull())
.append("decimal128", new BsonDecimal128(new Decimal128(55)));
InsertOneResult result = collection.insertOne(doc);
collection.insertOne(doc);

return "Insert=" + result;
return "InsertComplex";
}

@RequestMapping(value = "/mongodb/insertTo2ndserver")
Expand All @@ -183,8 +177,8 @@ public String insertTo2ndserver() {
public String insertNested() {
MongoCollection<Document> collection = getDatabase(DATABASE_NAME_2).getCollection(COLLECTION_NAME);
Document doc2 = new Document("name", "pinpoint2").append("company", new Document("nestedDoc", "1"));
InsertOneResult result = collection.insertOne(doc2);
return "Insert=" + result;
collection.insertOne(doc2);
return "InsertNested";
}

@RequestMapping(value = "/mongodb/insertArray")
Expand All @@ -197,16 +191,16 @@ public String insertArray() {
bsonArray.add(b);

Document doc = new Document("array", bsonArray);
InsertOneResult result = collection.insertOne(doc);
return "Insert=" + result;
collection.insertOne(doc);
return "InsertArray";
}

@RequestMapping(value = "/mongodb/insertCollection")
public String insertCollection() {
MongoCollection<Document> collection = getDatabase(DATABASE_NAME_2).getCollection(COLLECTION_NAME);
Document doc = new Document("Java_Collection", Arrays.asList("naver", "apple"));
InsertOneResult result = collection.insertOne(doc);
return "Insert=" + result;
collection.insertOne(doc);
return "InsertCollection";
}

@RequestMapping(value = "/mongodb/find")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,47 +1,10 @@
package com.pinpoint.test.plugin;

import de.flapdoodle.embed.mongo.MongodExecutable;
import de.flapdoodle.embed.mongo.MongodProcess;
import de.flapdoodle.embed.mongo.MongodStarter;
import de.flapdoodle.embed.mongo.config.MongodConfig;
import de.flapdoodle.embed.mongo.config.Net;
import de.flapdoodle.embed.mongo.distribution.Version;
import de.flapdoodle.embed.process.runtime.Network;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

@Component
public class MongoServer {
private MongodExecutable mongodExecutable;
private MongodProcess mongod;
private static final int PORT = 27017;
private static final int PORT = 62449;

public String getUri() {
public static String getUri() {
return "mongodb://localhost:" + PORT;
}


@PostConstruct
public void init() throws Exception {
MongodStarter starter = MongodStarter.getDefaultInstance();

MongodConfig mongodConfig = MongodConfig.builder()
.version(Version.Main.PRODUCTION)
.net(new Net(PORT, Network.localhostIsIPv6()))
.build();

this.mongodExecutable = starter.prepare(mongodConfig);
this.mongod = mongodExecutable.start();
}
@PreDestroy
public void destroy() {
if (mongod != null) {
mongod.stop();
}
if (mongodExecutable != null) {
mongodExecutable.stop();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright 2022 NAVER Corp.
*
* 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.
*/

package com.pinpoint.test.plugin.mongo;


import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.testcontainers.containers.MongoDBContainer;
import org.testcontainers.utility.DockerImageName;

import java.util.concurrent.TimeUnit;

public class MongodbTest {
private static MongoDBContainer container;

@BeforeClass
public static void beforeClass() {
// Assume.assumeTrue("Docker not enabled", DockerClientFactory.instance().isDockerAvailable());
container = new MongoDBContainer(DockerImageName.parse("mongo:4.0.10"));
container.start();

System.out.println("##host=" + container.getHost());
System.out.println("##port=" + container.getFirstMappedPort());
}

@AfterClass
public static void select() {
if (container != null) {
container.stop();
}
}

@Test
public void test() throws Exception {
System.out.println("TEST");
TimeUnit.HOURS.sleep(8);
}
}
39 changes: 23 additions & 16 deletions agent-testweb/mongodb-reactive-plugin-testweb/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,41 +16,48 @@
<pinpoint.agent.jvmargument>
${pinpoint.agent.default.jvmargument}
</pinpoint.agent.jvmargument>

<jdk.version>1.8</jdk.version>
<jdk.home>${env.JAVA_8_HOME}</jdk.home>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<artifactId>spring-boot-starter-webflux</artifactId>
<version>2.7.6</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
<artifactId>spring-boot-starter-data-mongodb-reactive</artifactId>
<version>2.7.6</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
<version>2.7.6</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<groupId>com.j2html</groupId>
<artifactId>j2html</artifactId>
</dependency>

<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.mongo</artifactId>
<version>${embed.mongo}</version>
<groupId>org.testcontainers</groupId>
<artifactId>mongodb</artifactId>
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-reactivestreams</artifactId>
<version>4.5.0</version>
</dependency>
</dependencies>

</project>
Loading

0 comments on commit 0a049cc

Please sign in to comment.