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