DATACOUCH-23 - Make tests clean buckets, Import cleanup.
This commit is contained in:
@@ -17,7 +17,6 @@
|
||||
package org.springframework.data.couchbase.cache;
|
||||
|
||||
import com.couchbase.client.CouchbaseClient;
|
||||
import net.spy.memcached.internal.OperationFuture;
|
||||
import org.springframework.cache.Cache;
|
||||
import org.springframework.cache.support.SimpleValueWrapper;
|
||||
|
||||
|
||||
@@ -17,12 +17,13 @@
|
||||
package org.springframework.data.couchbase.cache;
|
||||
|
||||
import com.couchbase.client.CouchbaseClient;
|
||||
import org.springframework.cache.Cache;
|
||||
import org.springframework.cache.support.AbstractCacheManager;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Map;
|
||||
import org.springframework.cache.Cache;
|
||||
import org.springframework.cache.support.AbstractCacheManager;
|
||||
|
||||
/**
|
||||
* The {@link CouchbaseCacheManager} orchestrates {@link CouchbaseCache} instances.
|
||||
|
||||
@@ -17,21 +17,22 @@
|
||||
package org.springframework.data.couchbase.config;
|
||||
|
||||
import com.couchbase.client.CouchbaseClient;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.type.filter.AnnotationTypeFilter;
|
||||
import org.springframework.data.annotation.Persistent;
|
||||
import org.springframework.data.couchbase.core.mapping.CouchbaseMappingContext;
|
||||
import org.springframework.data.couchbase.core.CouchbaseTemplate;
|
||||
import org.springframework.data.couchbase.core.convert.MappingCouchbaseConverter;
|
||||
import org.springframework.data.couchbase.core.mapping.CouchbaseMappingContext;
|
||||
import org.springframework.data.couchbase.core.mapping.Document;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Base class for Spring Data Couchbase configuration using JavaConfig.
|
||||
*
|
||||
|
||||
@@ -16,19 +16,17 @@
|
||||
|
||||
package org.springframework.data.couchbase.core;
|
||||
|
||||
import com.couchbase.client.ObservedException;
|
||||
import com.couchbase.client.ObservedModifiedException;
|
||||
import com.couchbase.client.ObservedTimeoutException;
|
||||
import com.couchbase.client.protocol.views.InvalidViewException;
|
||||
import com.couchbase.client.protocol.views.ViewException;
|
||||
import com.couchbase.client.vbucket.ConnectionException;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.DataAccessResourceFailureException;
|
||||
import org.springframework.dao.DataIntegrityViolationException;
|
||||
import org.springframework.dao.InvalidDataAccessResourceUsageException;
|
||||
import org.springframework.dao.support.PersistenceExceptionTranslator;
|
||||
|
||||
import com.couchbase.client.ObservedException;
|
||||
import com.couchbase.client.ObservedModifiedException;
|
||||
import com.couchbase.client.ObservedTimeoutException;
|
||||
import com.couchbase.client.vbucket.ConnectionException;
|
||||
|
||||
import java.util.concurrent.CancellationException;
|
||||
|
||||
|
||||
|
||||
@@ -17,13 +17,13 @@
|
||||
package org.springframework.data.couchbase.core;
|
||||
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import com.couchbase.client.protocol.views.Query;
|
||||
import com.couchbase.client.protocol.views.ViewResponse;
|
||||
import org.springframework.data.couchbase.core.convert.CouchbaseConverter;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Defines common operations on the Couchbase data source, most commonly implemented by {@link CouchbaseTemplate}.
|
||||
*
|
||||
|
||||
@@ -16,16 +16,12 @@
|
||||
|
||||
package org.springframework.data.couchbase.core;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import com.couchbase.client.CouchbaseClient;
|
||||
import com.couchbase.client.protocol.views.Query;
|
||||
import com.couchbase.client.protocol.views.View;
|
||||
import com.couchbase.client.protocol.views.ViewResponse;
|
||||
import com.couchbase.client.protocol.views.ViewRow;
|
||||
import net.spy.memcached.internal.OperationFuture;
|
||||
|
||||
import org.springframework.dao.QueryTimeoutException;
|
||||
import org.springframework.data.couchbase.core.convert.CouchbaseConverter;
|
||||
import org.springframework.data.couchbase.core.convert.MappingCouchbaseConverter;
|
||||
@@ -34,7 +30,9 @@ import org.springframework.data.couchbase.core.convert.translation.TranslationSe
|
||||
import org.springframework.data.couchbase.core.mapping.*;
|
||||
import org.springframework.data.mapping.context.MappingContext;
|
||||
|
||||
import com.couchbase.client.CouchbaseClient;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
/**
|
||||
* @author Michael Nitschinger
|
||||
|
||||
@@ -20,9 +20,7 @@ import org.springframework.data.mapping.model.SimpleTypeHolder;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Value object to capture custom conversion.
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package org.springframework.data.couchbase.core.convert;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
@@ -25,18 +23,23 @@ import org.springframework.core.CollectionFactory;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.core.convert.support.ConversionServiceFactory;
|
||||
import org.springframework.data.convert.EntityInstantiator;
|
||||
import org.springframework.data.couchbase.core.mapping.*;
|
||||
import org.springframework.data.couchbase.core.mapping.CouchbaseDocument;
|
||||
import org.springframework.data.couchbase.core.mapping.CouchbaseList;
|
||||
import org.springframework.data.couchbase.core.mapping.CouchbasePersistentEntity;
|
||||
import org.springframework.data.couchbase.core.mapping.CouchbasePersistentProperty;
|
||||
import org.springframework.data.mapping.Association;
|
||||
import org.springframework.data.mapping.AssociationHandler;
|
||||
import org.springframework.data.mapping.PreferredConstructor.Parameter;
|
||||
import org.springframework.data.mapping.PropertyHandler;
|
||||
import org.springframework.data.mapping.context.MappingContext;
|
||||
import org.springframework.data.mapping.model.*;
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
import org.springframework.data.mapping.PropertyHandler;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* The Couchbase special {@link MappingCouchbaseConverter}.
|
||||
*
|
||||
|
||||
@@ -16,13 +16,14 @@
|
||||
|
||||
package org.springframework.data.couchbase.core.mapping;
|
||||
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.lang.reflect.Field;
|
||||
import org.springframework.data.mapping.Association;
|
||||
import org.springframework.data.mapping.model.AnnotationBasedPersistentProperty;
|
||||
import org.springframework.data.mapping.model.SimpleTypeHolder;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
/**
|
||||
* Implements annotated property representations of a given Field instance.
|
||||
*
|
||||
|
||||
@@ -18,7 +18,10 @@ package org.springframework.data.couchbase.core.mapping;
|
||||
|
||||
import org.springframework.data.mapping.model.SimpleTypeHolder;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* A {@link CouchbaseList} is an abstract list that represents an array stored in a (most of the times JSON) document.
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package org.springframework.data.couchbase.core.mapping;
|
||||
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.lang.reflect.Field;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
@@ -25,6 +23,9 @@ import org.springframework.data.mapping.context.AbstractMappingContext;
|
||||
import org.springframework.data.mapping.model.SimpleTypeHolder;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
/**
|
||||
* Default implementation of a {@link org.springframework.data.mapping.context.MappingContext} for Couchbase using
|
||||
* {@link BasicCouchbasePersistentEntity} and {@link BasicCouchbasePersistentProperty} as primary abstractions.
|
||||
|
||||
@@ -16,13 +16,10 @@
|
||||
|
||||
package org.springframework.data.couchbase.core.mapping;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Inherited;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import org.springframework.data.annotation.Persistent;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* Identifies a domain object to be persisted to Couchbase.
|
||||
*
|
||||
|
||||
@@ -17,14 +17,10 @@
|
||||
package org.springframework.data.couchbase.monitor;
|
||||
|
||||
import com.couchbase.client.CouchbaseClient;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.http.converter.json.MappingJacksonHttpMessageConverter;
|
||||
import org.springframework.jmx.export.annotation.ManagedAttribute;
|
||||
import org.springframework.jmx.export.annotation.ManagedMetric;
|
||||
import org.springframework.jmx.export.annotation.ManagedResource;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,16 +16,11 @@
|
||||
|
||||
package org.springframework.data.couchbase.repository.config;
|
||||
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.context.annotation.ComponentScan.Filter;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.data.couchbase.repository.support.CouchbaseRepositoryFactoryBean;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Inherited;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* Annotation to activate Couchbase repositories. If no base package is configured through either {@link #value()},
|
||||
|
||||
@@ -23,9 +23,6 @@ import com.couchbase.client.protocol.views.ViewRow;
|
||||
import org.springframework.data.couchbase.core.CouchbaseOperations;
|
||||
import org.springframework.data.couchbase.repository.CouchbaseRepository;
|
||||
import org.springframework.data.couchbase.repository.query.CouchbaseEntityInformation;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@@ -16,34 +16,61 @@
|
||||
|
||||
package org.springframework.data.couchbase;
|
||||
|
||||
import com.couchbase.client.CouchbaseClient;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.Arrays;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.data.couchbase.config.AbstractCouchbaseConfiguration;
|
||||
import org.springframework.data.couchbase.core.convert.MappingCouchbaseConverter;
|
||||
import org.springframework.data.couchbase.core.mapping.CouchbaseMappingContext;
|
||||
import org.springframework.data.couchbase.util.BucketManager;
|
||||
|
||||
/**
|
||||
* @author Michael Nitschinger
|
||||
*/
|
||||
@Configuration
|
||||
public class TestApplicationConfig extends AbstractCouchbaseConfiguration {
|
||||
public class TestApplicationConfig {
|
||||
|
||||
@Autowired
|
||||
private Environment env;
|
||||
|
||||
@Bean
|
||||
@Override
|
||||
public CouchbaseClient couchbaseClient() throws IOException {
|
||||
String defaultHost = "http://127.0.0.1:8091/pools";
|
||||
String host = env.getProperty("couchbase.host", defaultHost);
|
||||
public String couchbaseHost() {
|
||||
return env.getProperty("couchbase.host", "http://127.0.0.1:8091/pools");
|
||||
}
|
||||
|
||||
String bucket = env.getProperty("couchbase.bucket", "default");
|
||||
String pass = env.getProperty("couchbase.password", "");
|
||||
return new CouchbaseClient(Arrays.asList(URI.create(host)), bucket, pass);
|
||||
@Bean
|
||||
public String couchbaseBucket() {
|
||||
return env.getProperty("couchbase.bucket", "default");
|
||||
}
|
||||
|
||||
@Bean
|
||||
public String couchbasePassword() {
|
||||
return env.getProperty("couchbase.password", "");
|
||||
}
|
||||
|
||||
@Bean
|
||||
public String couchbaseAdmin() {
|
||||
return env.getProperty("couchbase.admin", "Administrator");
|
||||
}
|
||||
|
||||
@Bean
|
||||
public String couchbaseAdminPassword() {
|
||||
return env.getProperty("couchbase.adminPassword", "password");
|
||||
}
|
||||
|
||||
@Bean
|
||||
public BucketManager bucketManager() {
|
||||
return new BucketManager(couchbaseHost(), couchbaseAdmin(), couchbaseAdminPassword());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MappingCouchbaseConverter mappingCouchbaseConverter() throws Exception {
|
||||
return new MappingCouchbaseConverter(couchbaseMappingContext());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CouchbaseMappingContext couchbaseMappingContext() throws Exception {
|
||||
return new CouchbaseMappingContext();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,16 +17,22 @@
|
||||
package org.springframework.data.couchbase.cache;
|
||||
|
||||
import com.couchbase.client.CouchbaseClient;
|
||||
import java.util.HashMap;
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.couchbase.TestApplicationConfig;
|
||||
import org.springframework.data.couchbase.cache.CouchbaseCacheManager;
|
||||
import org.springframework.data.couchbase.util.BucketCreationListener;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.TestExecutionListeners;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Verifies the correct functionality of the CouchbaseCacheManager.
|
||||
*
|
||||
@@ -34,14 +40,27 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = TestApplicationConfig.class)
|
||||
@TestExecutionListeners(BucketCreationListener.class)
|
||||
public class CouchbaseCacheManagerTest {
|
||||
|
||||
/**
|
||||
* Contains a reference to the actual CouchbaseClient.
|
||||
*/
|
||||
@Autowired
|
||||
private CouchbaseClient client;
|
||||
|
||||
@Autowired
|
||||
private String couchbaseHost;
|
||||
|
||||
@Autowired
|
||||
private String couchbaseBucket;
|
||||
|
||||
@Autowired
|
||||
private String couchbasePassword;
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
client = new CouchbaseClient(Arrays.asList(new URI(couchbaseHost)), couchbaseBucket, couchbasePassword);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the main functionality of the manager: loading the caches.
|
||||
|
||||
@@ -17,16 +17,22 @@
|
||||
package org.springframework.data.couchbase.cache;
|
||||
|
||||
import com.couchbase.client.CouchbaseClient;
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.Cache.ValueWrapper;
|
||||
import org.springframework.data.couchbase.TestApplicationConfig;
|
||||
import org.springframework.data.couchbase.cache.CouchbaseCache;
|
||||
import org.springframework.data.couchbase.util.BucketCreationListener;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.TestExecutionListeners;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Tests the CouchbaseCache class and verifies its functionality.
|
||||
*
|
||||
@@ -34,12 +40,12 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = TestApplicationConfig.class)
|
||||
@TestExecutionListeners(BucketCreationListener.class)
|
||||
public class CouchbaseCacheTest {
|
||||
|
||||
/**
|
||||
* Contains a reference to the actual CouchbaseClient.
|
||||
*/
|
||||
@Autowired
|
||||
private CouchbaseClient client;
|
||||
|
||||
/**
|
||||
@@ -47,6 +53,20 @@ public class CouchbaseCacheTest {
|
||||
*/
|
||||
private String cacheName = "test";
|
||||
|
||||
@Autowired
|
||||
private String couchbaseHost;
|
||||
|
||||
@Autowired
|
||||
private String couchbaseBucket;
|
||||
|
||||
@Autowired
|
||||
private String couchbasePassword;
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
client = new CouchbaseClient(Arrays.asList(new URI(couchbaseHost)), couchbaseBucket, couchbasePassword);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the basic Cache construction functionality.
|
||||
*/
|
||||
|
||||
@@ -17,17 +17,24 @@
|
||||
package org.springframework.data.couchbase.config;
|
||||
|
||||
import com.couchbase.client.CouchbaseClient;
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.data.couchbase.TestApplicationConfig;
|
||||
import org.springframework.data.couchbase.config.AbstractCouchbaseConfiguration;
|
||||
import org.springframework.data.couchbase.core.mapping.Document;
|
||||
import org.springframework.data.couchbase.util.BucketCreationListener;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.TestExecutionListeners;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Unit test for {@link AbstractCouchbaseConfiguration}
|
||||
*
|
||||
@@ -35,11 +42,28 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = TestApplicationConfig.class)
|
||||
@TestExecutionListeners(BucketCreationListener.class)
|
||||
public class AbstractCouchbaseConfigurationTest {
|
||||
|
||||
@Autowired
|
||||
/**
|
||||
* Contains a reference to the actual CouchbaseClient.
|
||||
*/
|
||||
private CouchbaseClient client;
|
||||
|
||||
@Autowired
|
||||
private String couchbaseHost;
|
||||
|
||||
@Autowired
|
||||
private String couchbaseBucket;
|
||||
|
||||
@Autowired
|
||||
private String couchbasePassword;
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
client = new CouchbaseClient(Arrays.asList(new URI(couchbaseHost)), couchbaseBucket, couchbasePassword);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void usesConfigClassPackageAsBaseMappingPackage() throws Exception {
|
||||
AbstractCouchbaseConfiguration config = new SampleCouchbaseConfiguration();
|
||||
|
||||
@@ -16,16 +16,14 @@
|
||||
|
||||
package org.springframework.data.couchbase.config;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionReader;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.springframework.data.couchbase.core;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.couchbase.core.CouchbaseTemplate;
|
||||
import org.springframework.data.couchbase.core.mapping.Field;
|
||||
|
||||
|
||||
|
||||
@@ -17,35 +17,52 @@
|
||||
package org.springframework.data.couchbase.core;
|
||||
|
||||
import com.couchbase.client.CouchbaseClient;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.couchbase.TestApplicationConfig;
|
||||
import org.springframework.data.couchbase.core.CouchbaseTemplate;
|
||||
import org.springframework.data.couchbase.core.mapping.Document;
|
||||
import org.springframework.data.couchbase.core.mapping.Field;
|
||||
import org.springframework.data.couchbase.util.BucketCreationListener;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.TestExecutionListeners;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import java.net.SocketAddress;
|
||||
import java.net.URI;
|
||||
import java.util.*;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Michael Nitschinger
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = TestApplicationConfig.class)
|
||||
@TestExecutionListeners(BucketCreationListener.class)
|
||||
public class CouchbaseTemplateTest {
|
||||
|
||||
@Autowired
|
||||
private CouchbaseClient client;
|
||||
|
||||
@Autowired
|
||||
private CouchbaseTemplate template;
|
||||
|
||||
@Autowired
|
||||
private String couchbaseHost;
|
||||
|
||||
@Autowired
|
||||
private String couchbaseBucket;
|
||||
|
||||
@Autowired
|
||||
private String couchbasePassword;
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
client = new CouchbaseClient(Arrays.asList(new URI(couchbaseHost)), couchbaseBucket, couchbasePassword);
|
||||
template = new CouchbaseTemplate(client);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void saveSimpleEntityCorrectly() throws Exception {
|
||||
String id = "beers:awesome-stout";
|
||||
@@ -101,13 +118,14 @@ public class CouchbaseTemplateTest {
|
||||
|
||||
@Test
|
||||
public void removeDocument() {
|
||||
String id = "beers:awesome-stout";
|
||||
String id = "beers:to-delete-stout";
|
||||
Beer beer = new Beer(id);
|
||||
|
||||
template.save(beer);
|
||||
Object result = client.get(id);
|
||||
assertNotNull(result);
|
||||
|
||||
Beer beer = new Beer(id);
|
||||
template.remove(beer);
|
||||
|
||||
result = client.get(id);
|
||||
assertNull(result);
|
||||
}
|
||||
|
||||
@@ -16,19 +16,17 @@
|
||||
|
||||
package org.springframework.data.couchbase.core.mapping;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.couchbase.core.mapping.BasicCouchbasePersistentEntity;
|
||||
import org.springframework.data.couchbase.core.mapping.BasicCouchbasePersistentProperty;
|
||||
import org.springframework.data.couchbase.core.mapping.CouchbasePersistentEntity;
|
||||
import org.springframework.data.couchbase.core.mapping.CouchbasePersistentProperty;
|
||||
import org.springframework.data.mapping.model.SimpleTypeHolder;
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Verifies the correct behavior of properties on persistable objects.
|
||||
*
|
||||
|
||||
@@ -28,9 +28,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Michael Nitschinger
|
||||
|
||||
@@ -22,10 +22,14 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.couchbase.TestApplicationConfig;
|
||||
import org.springframework.data.couchbase.monitor.ClientInfo;
|
||||
import org.springframework.data.couchbase.util.BucketCreationListener;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.TestExecutionListeners;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static junit.framework.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
@@ -34,15 +38,28 @@ import static org.junit.Assert.assertFalse;
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = TestApplicationConfig.class)
|
||||
@TestExecutionListeners(BucketCreationListener.class)
|
||||
public class ClientInfoTest {
|
||||
|
||||
@Autowired
|
||||
/**
|
||||
* Contains a reference to the actual CouchbaseClient.
|
||||
*/
|
||||
private CouchbaseClient client;
|
||||
|
||||
private ClientInfo ci;
|
||||
|
||||
@Autowired
|
||||
private String couchbaseHost;
|
||||
|
||||
@Autowired
|
||||
private String couchbaseBucket;
|
||||
|
||||
@Autowired
|
||||
private String couchbasePassword;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
public void setup() throws Exception {
|
||||
client = new CouchbaseClient(Arrays.asList(new URI(couchbaseHost)), couchbaseBucket, couchbasePassword);
|
||||
ci = new ClientInfo(client);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,28 +22,43 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.couchbase.TestApplicationConfig;
|
||||
import org.springframework.data.couchbase.monitor.ClusterInfo;
|
||||
import org.springframework.data.couchbase.util.BucketCreationListener;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.TestExecutionListeners;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static junit.framework.Assert.assertNotNull;
|
||||
import java.net.URI;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
/**
|
||||
* @author Michael Nitschinger
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = TestApplicationConfig.class)
|
||||
@TestExecutionListeners(BucketCreationListener.class)
|
||||
public class ClusterInfoTest {
|
||||
|
||||
@Autowired
|
||||
/**
|
||||
* Contains a reference to the actual CouchbaseClient.
|
||||
*/
|
||||
private CouchbaseClient client;
|
||||
|
||||
private ClusterInfo ci;
|
||||
|
||||
@Autowired
|
||||
private String couchbaseHost;
|
||||
|
||||
@Autowired
|
||||
private String couchbaseBucket;
|
||||
|
||||
@Autowired
|
||||
private String couchbasePassword;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
public void setup() throws Exception {
|
||||
client = new CouchbaseClient(Arrays.asList(new URI(couchbaseHost)), couchbaseBucket, couchbasePassword);
|
||||
ci = new ClusterInfo(client);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,31 +16,52 @@
|
||||
|
||||
package org.springframework.data.couchbase.repository;
|
||||
|
||||
import com.couchbase.client.CouchbaseClient;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.couchbase.TestApplicationConfig;
|
||||
import org.springframework.data.couchbase.core.CouchbaseTemplate;
|
||||
import org.springframework.data.couchbase.repository.support.CouchbaseRepositoryFactory;
|
||||
import org.springframework.data.couchbase.util.BucketCreationListener;
|
||||
import org.springframework.data.repository.core.support.RepositoryFactorySupport;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.TestExecutionListeners;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import java.net.URI;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Michael Nitschinger
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = TestApplicationConfig.class)
|
||||
@TestExecutionListeners(BucketCreationListener.class)
|
||||
public class SimpleCouchbaseRepositoryTest {
|
||||
|
||||
@Autowired
|
||||
private CouchbaseClient client;
|
||||
|
||||
private CouchbaseTemplate template;
|
||||
|
||||
@Autowired
|
||||
private String couchbaseHost;
|
||||
|
||||
@Autowired
|
||||
private String couchbaseBucket;
|
||||
|
||||
@Autowired
|
||||
private String couchbasePassword;
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
client = new CouchbaseClient(Arrays.asList(new URI(couchbaseHost)), couchbaseBucket, couchbasePassword);
|
||||
template = new CouchbaseTemplate(client);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void simpleCrud() {
|
||||
String key = "my_unique_user_key";
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package org.springframework.data.couchbase.repository;
|
||||
|
||||
import org.springframework.data.couchbase.repository.CouchbaseRepository;
|
||||
|
||||
/**
|
||||
* @author Michael Nitschinger
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package org.springframework.data.couchbase.util;
|
||||
|
||||
import com.couchbase.client.CouchbaseClient;
|
||||
import com.couchbase.client.clustermanager.BucketType;
|
||||
import org.springframework.test.context.TestContext;
|
||||
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Arrays;
|
||||
|
||||
|
||||
public class BucketCreationListener extends DependencyInjectionTestExecutionListener {
|
||||
|
||||
private CouchbaseClient client;
|
||||
|
||||
@Override
|
||||
public void beforeTestClass(final TestContext testContext) throws Exception {
|
||||
|
||||
BucketManager bucketManager = (BucketManager) testContext.getApplicationContext().getBean("bucketManager");
|
||||
|
||||
bucketManager.deleteAllBuckets();
|
||||
bucketManager.createDefaultBucket(BucketType.COUCHBASE, 256, 1, true);
|
||||
BucketManager.FunctionCallback callback = new BucketManager.FunctionCallback() {
|
||||
|
||||
@Override
|
||||
public void callback() throws Exception {
|
||||
initTemplate(testContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String success(long elapsedTime) {
|
||||
return "Bucket clearance took " + elapsedTime + "ms";
|
||||
}
|
||||
};
|
||||
|
||||
bucketManager.poll(callback);
|
||||
bucketManager.waitForWarmup(client);
|
||||
}
|
||||
|
||||
|
||||
protected void initTemplate(final TestContext testContext) throws Exception {
|
||||
String host = (String) testContext.getApplicationContext().getBean("couchbaseHost");
|
||||
String bucket = (String) testContext.getApplicationContext().getBean("couchbaseBucket");
|
||||
String password = (String) testContext.getApplicationContext().getBean("couchbasePassword");
|
||||
|
||||
client = new CouchbaseClient(Arrays.asList(new URI(host)), bucket, password);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
/*
|
||||
* Copyright 2013 the original 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.
|
||||
*/
|
||||
|
||||
package org.springframework.data.couchbase.util;
|
||||
|
||||
import com.couchbase.client.ClusterManager;
|
||||
import com.couchbase.client.clustermanager.BucketType;
|
||||
import net.spy.memcached.MemcachedClient;
|
||||
import net.spy.memcached.compat.SpyObject;
|
||||
|
||||
import java.net.SocketAddress;
|
||||
import java.net.URI;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
/**
|
||||
* A helper class for test cases that retries bucket creation, deletion, and
|
||||
* warmup since these processes can take a long time.
|
||||
*
|
||||
* @author Michael Nitschinger
|
||||
*/
|
||||
public class BucketManager extends SpyObject {
|
||||
|
||||
private static final long TIMEOUT = 120000;
|
||||
private static final long SLEEP_TIME = 2000;
|
||||
|
||||
private final ClusterManager manager;
|
||||
|
||||
public BucketManager(String host, String admin, String pass) {
|
||||
List<URI> uris = new LinkedList<URI>();
|
||||
uris.add(URI.create(host));
|
||||
manager = new ClusterManager(uris, admin, pass);
|
||||
}
|
||||
|
||||
/**
|
||||
* A class for defining a simple callback. Used to define your own poll
|
||||
* function.
|
||||
*/
|
||||
public static class FunctionCallback {
|
||||
public void callback() throws Exception {
|
||||
throw new UnsupportedOperationException("Must override this function");
|
||||
}
|
||||
|
||||
public String success(long elapsedTime) {
|
||||
throw new UnsupportedOperationException("Must override this function");
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteAllBuckets() throws Exception {
|
||||
FunctionCallback callback = new FunctionCallback() {
|
||||
@Override
|
||||
public void callback() throws Exception {
|
||||
List<String> buckets = manager.listBuckets();
|
||||
for (int i = 0; i < buckets.size(); i++) {
|
||||
manager.deleteBucket(buckets.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String success(long elapsedTime) {
|
||||
return "Bucket deletion took " + elapsedTime + "ms";
|
||||
}
|
||||
};
|
||||
poll(callback);
|
||||
}
|
||||
|
||||
public void createDefaultBucket(final BucketType type, final int quota,
|
||||
final int replicas, final boolean flush) throws Exception {
|
||||
FunctionCallback callback = new FunctionCallback() {
|
||||
@Override
|
||||
public void callback() throws Exception {
|
||||
manager.createDefaultBucket(type, quota, replicas, flush);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String success(long elapsedTime) {
|
||||
return "Bucket creation took " + elapsedTime + "ms";
|
||||
}
|
||||
};
|
||||
poll(callback);
|
||||
}
|
||||
|
||||
public void createSaslBucket(final String name, final BucketType type,
|
||||
final int quota, final int replicas, final boolean flush) throws Exception {
|
||||
FunctionCallback callback = new FunctionCallback() {
|
||||
@Override
|
||||
public void callback() throws Exception {
|
||||
manager.createNamedBucket(type, name, quota, replicas, name, flush);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String success(long elapsedTime) {
|
||||
return "Bucket creation took " + elapsedTime + "ms";
|
||||
}
|
||||
};
|
||||
poll(callback);
|
||||
}
|
||||
|
||||
public void poll(FunctionCallback cb) throws Exception {
|
||||
long st = System.currentTimeMillis();
|
||||
|
||||
while (true) {
|
||||
try {
|
||||
cb.callback();
|
||||
getLogger().info(cb.success(System.currentTimeMillis() - st));
|
||||
return;
|
||||
} catch (RuntimeException e) {
|
||||
if ((System.currentTimeMillis() - st) > TIMEOUT) {
|
||||
throw e;
|
||||
}
|
||||
Thread.sleep(SLEEP_TIME);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void waitForWarmup(MemcachedClient client) throws Exception {
|
||||
boolean warmup = true;
|
||||
while (warmup) {
|
||||
warmup = false;
|
||||
Map<SocketAddress, Map<String, String>> stats = client.getStats();
|
||||
for (Entry<SocketAddress, Map<String, String>> server: stats.entrySet()) {
|
||||
Map<String, String> serverStats = server.getValue();
|
||||
if (!serverStats.containsKey("ep_degraded_mode")) {
|
||||
warmup = true;
|
||||
Thread.sleep(1000);
|
||||
break;
|
||||
}
|
||||
if (!serverStats.get("ep_degraded_mode").equals("0")) {
|
||||
warmup = true;
|
||||
Thread.sleep(1000);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user