Cleanup tests
This commit is contained in:
parent
444cbecba5
commit
f5590e97bd
|
@ -1,5 +1,6 @@
|
|||
package springdata
|
||||
|
||||
import com.couchbase.client.java.cluster.BucketSettings
|
||||
import com.couchbase.client.java.env.CouchbaseEnvironment
|
||||
import org.springframework.context.annotation.ComponentScan
|
||||
import org.springframework.context.annotation.Configuration
|
||||
|
@ -13,8 +14,9 @@ import static com.google.common.base.Preconditions.checkNotNull
|
|||
@ComponentScan(basePackages = "springdata")
|
||||
class CouchbaseConfig extends AbstractCouchbaseConfiguration {
|
||||
|
||||
// This needs to be set before this class can be used by Spring
|
||||
// These need to be set before this class can be used by Spring
|
||||
static CouchbaseEnvironment environment
|
||||
static BucketSettings bucketSettings
|
||||
|
||||
@Override
|
||||
protected CouchbaseEnvironment getEnvironment() {
|
||||
|
@ -28,12 +30,12 @@ class CouchbaseConfig extends AbstractCouchbaseConfiguration {
|
|||
|
||||
@Override
|
||||
protected String getBucketName() {
|
||||
return "CouchbaseSpringRepositoryTest-cb"
|
||||
return bucketSettings.name()
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getBucketPassword() {
|
||||
return "test-pass"
|
||||
return bucketSettings.password()
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package springdata
|
|||
|
||||
import com.couchbase.client.java.view.DefaultView
|
||||
import com.couchbase.client.java.view.DesignDocument
|
||||
import org.springframework.context.ApplicationContext
|
||||
import org.springframework.context.ConfigurableApplicationContext
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext
|
||||
import org.springframework.data.repository.CrudRepository
|
||||
import spock.lang.Shared
|
||||
|
@ -26,7 +26,7 @@ class CouchbaseSpringRepositoryTest extends AbstractCouchbaseTest {
|
|||
}
|
||||
}
|
||||
@Shared
|
||||
ApplicationContext applicationContext
|
||||
ConfigurableApplicationContext applicationContext
|
||||
@Shared
|
||||
DocRepository repo
|
||||
|
||||
|
@ -46,6 +46,7 @@ class CouchbaseSpringRepositoryTest extends AbstractCouchbaseTest {
|
|||
)))
|
||||
)
|
||||
CouchbaseConfig.setEnvironment(couchbaseEnvironment)
|
||||
CouchbaseConfig.setBucketSettings(bucketCouchbase)
|
||||
|
||||
// Close all buckets and disconnect
|
||||
couchbaseCluster.disconnect()
|
||||
|
@ -54,6 +55,10 @@ class CouchbaseSpringRepositoryTest extends AbstractCouchbaseTest {
|
|||
repo = applicationContext.getBean(DocRepository)
|
||||
}
|
||||
|
||||
def cleanupSpec() {
|
||||
applicationContext.close()
|
||||
}
|
||||
|
||||
def setup() {
|
||||
repo.deleteAll()
|
||||
TEST_WRITER.waitForTraces(1) // There might be more if there were documents to delete
|
||||
|
@ -139,12 +144,9 @@ class CouchbaseSpringRepositoryTest extends AbstractCouchbaseTest {
|
|||
|
||||
then: // UPDATE
|
||||
repo.save(doc) == doc
|
||||
FIND(repo, "1") == doc
|
||||
// findAll doesn't seem to be working.
|
||||
// repo.findAll().asList() == [doc]
|
||||
repo.findAll().asList() == [doc]
|
||||
|
||||
and:
|
||||
assertTraces(TEST_WRITER, 2) {
|
||||
assertTraces(TEST_WRITER, 3) {
|
||||
trace(0, 1) {
|
||||
span(0) {
|
||||
serviceName "couchbase"
|
||||
|
@ -159,6 +161,19 @@ class CouchbaseSpringRepositoryTest extends AbstractCouchbaseTest {
|
|||
}
|
||||
}
|
||||
trace(1, 1) {
|
||||
span(0) {
|
||||
serviceName "couchbase"
|
||||
resourceName "Bucket.query(${bucketCouchbase.name()})"
|
||||
operationName "couchbase.call"
|
||||
errored false
|
||||
parent()
|
||||
tags {
|
||||
"bucket" bucketCouchbase.name()
|
||||
defaultTags()
|
||||
}
|
||||
}
|
||||
}
|
||||
trace(2, 1) {
|
||||
span(0) {
|
||||
serviceName "couchbase"
|
||||
resourceName "Bucket.get(${bucketCouchbase.name()})"
|
||||
|
|
|
@ -18,6 +18,7 @@ import datadog.trace.agent.test.AgentTestRunner
|
|||
import datadog.trace.agent.test.TestUtils
|
||||
import spock.lang.Shared
|
||||
|
||||
import java.util.concurrent.RejectedExecutionException
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
abstract class AbstractCouchbaseTest extends AgentTestRunner {
|
||||
|
@ -99,8 +100,16 @@ abstract class AbstractCouchbaseTest extends AgentTestRunner {
|
|||
}
|
||||
|
||||
def cleanupSpec() {
|
||||
try {
|
||||
couchbaseCluster?.disconnect()
|
||||
} catch (RejectedExecutionException e) {
|
||||
// already closed by a test?
|
||||
}
|
||||
try {
|
||||
memcacheCluster?.disconnect()
|
||||
} catch (RejectedExecutionException e) {
|
||||
// already closed by a test?
|
||||
}
|
||||
|
||||
mock?.stop()
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ class Config {
|
|||
|
||||
System.addShutdownHook {
|
||||
if (tmpDir != null) {
|
||||
FileSystemUtils.deleteSubDirectories(esWorkingDir.toPath())
|
||||
FileSystemUtils.deleteSubDirectories(tmpDir.toPath())
|
||||
tmpDir.delete()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue