public class MongoDBResourceManager extends TestContainerResourceManager<MongoDBContainer> implements org.apache.beam.it.common.ResourceManager
The class supports one database and multiple collections per database object. A database is created when the first collection is created if one has not been created already.
The database name is formed using testId. The database name will be "{testId}-{ISO8601 time, microsecond precision}", with additional formatting.
The class is thread-safe.
Modifier and Type | Class and Description |
---|---|
static class |
MongoDBResourceManager.Builder
Builder for
MongoDBResourceManager . |
HOST_IP, port
Modifier and Type | Method and Description |
---|---|
static MongoDBResourceManager.Builder |
builder(java.lang.String testId) |
void |
cleanupAll()
Deletes all created resources (VM's, etc.) and stops the container, making the manager object
unusable.
|
long |
countCollection(java.lang.String collectionName)
Counts the number of Documents in a collection.
|
boolean |
createCollection(java.lang.String collectionName)
Creates a collection in MongoDB for storing Documents.
|
java.lang.String |
getDatabaseName()
Returns the name of the Database that this MongoDB manager will operate in.
|
java.lang.String |
getUri()
Returns the URI connection string to the MongoDB Database.
|
boolean |
insertDocument(java.lang.String collectionName,
org.bson.Document document)
Inserts the given Document into a collection.
|
boolean |
insertDocuments(java.lang.String collectionName,
java.util.List<org.bson.Document> documents)
Inserts the given Documents into a collection.
|
java.util.List<org.bson.Document> |
readCollection(java.lang.String collectionName)
Reads all the Documents in a collection.
|
getDockerImageName, getHost, getPort
public static MongoDBResourceManager.Builder builder(java.lang.String testId)
public java.lang.String getUri()
public java.lang.String getDatabaseName()
public boolean createCollection(java.lang.String collectionName) throws MongoDBResourceManagerException
Note: Implementations may do database creation here, if one does not already exist.
collectionName
- Collection name to associate with the given MongoDB instance.MongoDBResourceManagerException
- if there is an error creating the collection in
MongoDB.public boolean insertDocument(java.lang.String collectionName, org.bson.Document document)
A database will be created here, if one does not already exist.
collectionName
- The name of the collection to insert the document into.document
- The document to insert into the collection.public boolean insertDocuments(java.lang.String collectionName, java.util.List<org.bson.Document> documents) throws MongoDBResourceManagerException
Note: Implementations may do collection creation here, if one does not already exist.
collectionName
- The name of the collection to insert the documents into.documents
- A list of documents to insert into the collection.MongoDBResourceManagerException
- if there is an error inserting the documents.public java.util.List<org.bson.Document> readCollection(java.lang.String collectionName) throws MongoDBResourceManagerException
collectionName
- The name of the collection to read from.MongoDBResourceManagerException
- if there is an error reading the collection.public long countCollection(java.lang.String collectionName) throws MongoDBResourceManagerException
collectionName
- The name of the collection to read from.MongoDBResourceManagerException
- if there is an error reading the collection.public void cleanupAll()
TestContainerResourceManager
cleanupAll
in interface org.apache.beam.it.common.ResourceManager
cleanupAll
in class TestContainerResourceManager<MongoDBContainer>