From d015c55d5f2ad081b28def6a6414de669ecf2e70 Mon Sep 17 00:00:00 2001 From: "J. Brisbin" Date: Thu, 11 Nov 2010 16:52:11 -0600 Subject: [PATCH] Test coverage on most functionality. get/set operations. --- .gitignore | 3 + pom.xml | 328 +++--- spring-datastore-keyvalue-parent/pom.xml | 955 +++++++++--------- spring-datastore-riak/pom.xml | 207 ++-- .../DataStoreConnectionFailureException.java | 34 + .../riak/DataStoreOperationException.java | 34 + .../riak/convert/KeyValueStoreMetaData.java | 32 + .../riak/convert/RiakConversionService.java | 28 + .../riak/core/AbstractAsyncOperation.java | 43 + .../datastore/riak/core/KeyValueStoreKey.java | 59 ++ .../riak/core/KeyValueStoreOperations.java | 70 ++ .../riak/core/RiakOperationCallback.java | 28 + .../datastore/riak/core/RiakTemplate.java | 305 ++++++ .../riak/mapreduce/MapReduceJob.java | 33 + .../riak/mapreduce/MapReduceOperations.java | 31 + .../riak/mapreduce/MapReducePhase.java | 28 + .../riak/mapreduce/RiakMapReduceJob.java | 55 + .../riak/mapreduce/RiakMapReducePhase.java | 32 + .../resources/META-INF/spring/app-context.xml | 8 +- .../core/RiakTemplateIntegrationTests.java | 63 +- .../riak/core/RiakTemplateSpec.groovy | 156 +++ .../datastore/riak/core/TestObject.java | 41 + .../src/test/resources/log4j.properties | 3 +- .../datastore/RiakTemplateTests.xml | 10 + spring-datastore-riak/template.mf | 12 +- 25 files changed, 1865 insertions(+), 733 deletions(-) create mode 100644 spring-datastore-riak/src/main/java/org/springframework/datastore/riak/DataStoreConnectionFailureException.java create mode 100644 spring-datastore-riak/src/main/java/org/springframework/datastore/riak/DataStoreOperationException.java create mode 100644 spring-datastore-riak/src/main/java/org/springframework/datastore/riak/convert/KeyValueStoreMetaData.java create mode 100644 spring-datastore-riak/src/main/java/org/springframework/datastore/riak/convert/RiakConversionService.java create mode 100644 spring-datastore-riak/src/main/java/org/springframework/datastore/riak/core/AbstractAsyncOperation.java create mode 100644 spring-datastore-riak/src/main/java/org/springframework/datastore/riak/core/KeyValueStoreKey.java create mode 100644 spring-datastore-riak/src/main/java/org/springframework/datastore/riak/core/KeyValueStoreOperations.java create mode 100644 spring-datastore-riak/src/main/java/org/springframework/datastore/riak/core/RiakOperationCallback.java create mode 100644 spring-datastore-riak/src/main/java/org/springframework/datastore/riak/core/RiakTemplate.java create mode 100644 spring-datastore-riak/src/main/java/org/springframework/datastore/riak/mapreduce/MapReduceJob.java create mode 100644 spring-datastore-riak/src/main/java/org/springframework/datastore/riak/mapreduce/MapReduceOperations.java create mode 100644 spring-datastore-riak/src/main/java/org/springframework/datastore/riak/mapreduce/MapReducePhase.java create mode 100644 spring-datastore-riak/src/main/java/org/springframework/datastore/riak/mapreduce/RiakMapReduceJob.java create mode 100644 spring-datastore-riak/src/main/java/org/springframework/datastore/riak/mapreduce/RiakMapReducePhase.java create mode 100644 spring-datastore-riak/src/test/java/org/springframework/datastore/riak/core/RiakTemplateSpec.groovy create mode 100644 spring-datastore-riak/src/test/java/org/springframework/datastore/riak/core/TestObject.java create mode 100644 spring-datastore-riak/src/test/resources/org/springframework/datastore/RiakTemplateTests.xml diff --git a/.gitignore b/.gitignore index aee5425d5..55b3d0f62 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,6 @@ target .springBeans .ant-targets-build.xml src/ant/.ant-targets-upload-dist.xml +*.iml +*.ipr +*.iws diff --git a/pom.xml b/pom.xml index e1d7b5a89..7a8e50951 100644 --- a/pom.xml +++ b/pom.xml @@ -1,171 +1,181 @@ - 4.0.0 - org.springframework.data - spring-datastore-keyvalue-dist - Spring Datastore Key-Value Distribution - 1.0.0.BUILD-SNAPSHOT - pom + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + 4.0.0 + org.springframework.data + spring-datastore-keyvalue-dist + Spring Datastore Key-Value Distribution + 1.0.0.BUILD-SNAPSHOT + pom - - spring-datastore-keyvalue-parent - spring-datastore-keyvalue-core - spring-datastore-redis - spring-datastore-riak - + + spring-datastore-keyvalue-parent + spring-datastore-keyvalue-core + spring-datastore-redis + spring-datastore-riak + - - - - org.springframework.build.aws - org.springframework.build.aws.maven - 2.0.0.RELEASE - - + + + + org.springframework.build.aws + org.springframework.build.aws.maven + 2.0.0.RELEASE + + - - - com.agilejava.docbkx - docbkx-maven-plugin - 2.0.7 - - - - generate-html - generate-pdf - - pre-site - - - - - org.docbook - docbook-xml - 4.4 - runtime - - - - index.xml - true - ${project.basedir}/src/docbkx/resources/xsl/fopdf.xsl - css/html.css - false - ${project.basedir}/src/docbkx/resources/xsl/html.xsl + + + maven-compiler-plugin + + 1.6 + 1.6 + + + + + com.agilejava.docbkx + docbkx-maven-plugin + 2.0.7 + + + + generate-html + generate-pdf + + pre-site + + + + + org.docbook + docbook-xml + 4.4 + runtime + + + + index.xml + true + ${project.basedir}/src/docbkx/resources/xsl/fopdf.xsl + css/html.css + false + ${project.basedir}/src/docbkx/resources/xsl/html.xsl 1 1 - - - - - version - ${pom.version} - - - - - - - - - - - - - - - - - - - - - + + + + + version + ${pom.version} + + + + + + + + + + + + + + + + + + + + + - + + run `mvn package assembly:assembly` to trigger assembly creation. + see http://www.sonatype.com/books/mvnref-book/reference/assemblies-set-dist-assemblies.html + maven-assembly-plugin + 2.2-beta-5 + false + + + distribution + + single + + package + + + ${project.basedir}/src/assembly/distribution.xml + + false + + + + + + org.apache.maven.plugins + maven-antrun-plugin + 1.4 + + + upload-dist + deploy + + + + + + + + + run + + + + + + org.springframework.build + org.springframework.build.aws.ant + 3.0.5.RELEASE + + + net.java.dev.jets3t + jets3t + 0.7.2 + + + + + + ${dist.finalName} + --> + - - - - - http://www.springsource.com/spring-data - - static.springframework.org - scp://static.springframework.org/var/www/domains/springframework.org/static/htdocs/spring-data/datastore-keyvalue/snapshot-site/ - - - spring-milestone - Spring Milestone Repository - s3://maven.springframework.org/milestone - - - spring-snapshot - Spring Snapshot Repository - s3://maven.springframework.org/snapshot - - + + + + + http://www.springsource.com/spring-data + + static.springframework.org + + scp://static.springframework.org/var/www/domains/springframework.org/static/htdocs/spring-data/datastore-keyvalue/snapshot-site/ + + + + spring-milestone + Spring Milestone Repository + s3://maven.springframework.org/milestone + + + spring-snapshot + Spring Snapshot Repository + s3://maven.springframework.org/snapshot + + \ No newline at end of file diff --git a/spring-datastore-keyvalue-parent/pom.xml b/spring-datastore-keyvalue-parent/pom.xml index 7ef22c273..f05fed345 100644 --- a/spring-datastore-keyvalue-parent/pom.xml +++ b/spring-datastore-keyvalue-parent/pom.xml @@ -1,479 +1,514 @@ - 4.0.0 - org.springframework.data - spring-datastore-keyvalue-parent - Spring Datastore Key-Value Parent - http://www.springsource.org/spring-data/datastore-keyvalue - 1.0.0.BUILD-SNAPSHOT - pom + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + 4.0.0 + org.springframework.data + spring-datastore-keyvalue-parent + Spring Datastore Key-Value Parent + http://www.springsource.org/spring-data/datastore-keyvalue + 1.0.0.BUILD-SNAPSHOT + pom + + + UTF-8 + + 4.8.1 + 1.2.15 + 1.5.6 + 1.8.4 + 1.5.10 + 3.0.5.RELEASE + + spring-datastore-keyvalue + Spring Datastore Key-Value + DATADOC + ${project.version} + snapshot + ${dist.id}-${dist.version} + ${dist.finalName}.zip + target/${dist.fileName} + dist.springframework.org + + - - UTF-8 - - 4.8.1 - 1.2.15 - 1.8.4 - 1.5.10 - 3.0.5.RELEASE - - spring-datastore-keyvalue - Spring Datastore Key-Value - DATADOC - ${project.version} - snapshot - ${dist.id}-${dist.version} - ${dist.finalName}.zip - target/${dist.fileName} - dist.springframework.org - - - - - - mpollack - Mark Pollack - mpollack at vmware.com - SpringSource - http://www.SpringSource.com - - Project Admin - Developer - - -5 - - - cleau - Costin Leau - cleau at vmware.com - SpringSource - http://www.SpringSource.com - - Developer - - +2 - + + mpollack + Mark Pollack + mpollack at vmware.com + SpringSource + http://www.SpringSource.com + + Project Admin + Developer + + -5 + + + cleau + Costin Leau + cleau at vmware.com + SpringSource + http://www.SpringSource.com + + Developer + + +2 + - + - - - Apache License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0 - - Copyright 2010 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. - - - + + + Apache License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0 + + Copyright 2010 the original author or authors. - - - strict - - false - - - - fast - - true - true - - - - staging - - - spring-site-staging - file:///${java.io.tmpdir}/spring-data/datastore-keyvalue/docs - - - spring-milestone-staging - file:///${java.io.tmpdir}/spring-data/datastore-keyvalue/milestone - - - spring-snapshot-staging - file:///${java.io.tmpdir}/spring-data/datastore-keyvalue/snapshot - - - - - bootstrap - - - + 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 - - - org.springframework - spring-aop - ${org.springframework.version} - - - org.springframework - spring-beans - ${org.springframework.version} - - - org.springframework - spring-core - ${org.springframework.version} - - - commons-logging - commons-logging - - - - - org.springframework - spring-tx - ${org.springframework.version} - - - org.springframework - spring-test - ${org.springframework.version} - test - + 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. + + + - - - org.springframework.data - spring-datastore-keyvalue-core - ${project.version} - - - org.springframework.data - spring-datastore-redis - ${project.version} - + + + strict + + false + + + + fast + + true + true + + + + staging + + + spring-site-staging + file:///${java.io.tmpdir}/spring-data/datastore-keyvalue/docs + + + spring-milestone-staging + file:///${java.io.tmpdir}/spring-data/datastore-keyvalue/milestone + + + spring-snapshot-staging + file:///${java.io.tmpdir}/spring-data/datastore-keyvalue/snapshot + + + + + bootstrap + + + - - - org.slf4j - slf4j-api - ${org.slf4j.version} - - - org.slf4j - jcl-over-slf4j - ${org.slf4j.version} - runtime - - - org.slf4j - slf4j-log4j12 - ${org.slf4j.version} - runtime - - - log4j - log4j - ${log4j.version} - - - javax.mail - mail - - - javax.jms - jms - - - com.sun.jdmk - jmxtools - - - com.sun.jmx - jmxri - - - runtime - + + + - - javax.annotation - jsr250-api - 1.0 - true - + + + org.springframework + spring-aop + ${org.springframework.version} + + + org.springframework + spring-beans + ${org.springframework.version} + + + org.springframework + spring-core + ${org.springframework.version} + + + commons-logging + commons-logging + + + + + org.springframework + spring-tx + ${org.springframework.version} + + + org.springframework + spring-test + ${org.springframework.version} + test + + + org.springframework + spring-web + ${org.springframework.version} + - - org.mockito - mockito-all - ${org.mockito.version} - test - + + + org.springframework.data + spring-datastore-keyvalue-core + ${project.version} + + + org.springframework.data + spring-datastore-redis + ${project.version} + - - junit - junit - ${junit.version} - test - + + + org.codehaus.jackson + jackson-core-asl + ${org.codehaus.jackson.version} + + + org.codehaus.jackson + jackson-mapper-asl + ${org.codehaus.jackson.version} + - - - - - - log4j - log4j - ${log4j.version} - test - - + + + org.slf4j + slf4j-api + ${org.slf4j.version} + + + org.slf4j + jcl-over-slf4j + ${org.slf4j.version} + runtime + + + org.slf4j + slf4j-log4j12 + ${org.slf4j.version} + runtime + + + log4j + log4j + ${log4j.version} + + + javax.mail + mail + + + javax.jms + jms + + + com.sun.jdmk + jmxtools + + + com.sun.jmx + jmxri + + + runtime + - - - - org.springframework.build.aws - org.springframework.build.aws.maven - 2.0.0.RELEASE - - - - - ${project.basedir}/src/main/java - - **/* - - - **/*.java - - - - ${project.basedir}/src/main/resources - - **/* - - - - - - ${project.basedir}/src/test/java - - **/* - - - **/*.java - - - - ${project.basedir}/src/test/resources - - **/* - - - **/*.java - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - 1.5 - 1.5 - -Xlint:all - true - false - - - - org.apache.maven.plugins - maven-surefire-plugin - - false - - **/*Tests.java - - - **/Abstract*.java - - - junit:junit - - - - - - - - - com.springsource.bundlor - com.springsource.bundlor.maven - 1.0.0.RELEASE - - true - - - - bundlor - - bundlor - - - - - - - - - - - - repository.plugin.springsource.release - SpringSource Maven Repository - http://repository.springsource.com/maven/bundles/release - - - - - repository.springframework.maven.release - Spring Framework Maven Release Repository - http://maven.springframework.org/release - - - repository.springframework.maven.milestone - Spring Framework Maven Milestone Repository - http://maven.springframework.org/milestone - - - repository.springframework.maven.snapshot - Spring Framework Maven Snapshot Repository - http://maven.springframework.org/snapshot - + + javax.annotation + jsr250-api + 1.0 + true + + + + org.mockito + mockito-all + ${org.mockito.version} + test + + + + junit + junit + ${junit.version} + test + + + org.spockframework + spock-spring + 0.5-groovy-1.7-SNAPSHOT + test + + + + + + + + log4j + log4j + ${log4j.version} + test + + + + + + + org.springframework.build.aws + org.springframework.build.aws.maven + 2.0.0.RELEASE + + + + + ${project.basedir}/src/main/java + + **/* + + + **/*.java + + + + ${project.basedir}/src/main/resources + + **/* + + + + + + ${project.basedir}/src/test/java + + **/* + + + **/*.java + + + + ${project.basedir}/src/test/resources + + **/* + + + **/*.java + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.5 + 1.5 + -Xlint:all + true + false + + + + org.apache.maven.plugins + maven-surefire-plugin + + false + + **/*Tests.java + + + **/Abstract*.java + + + junit:junit + + + + + + + + + com.springsource.bundlor + com.springsource.bundlor.maven + 1.0.0.RELEASE + + true + + + + bundlor + + bundlor + + + + + + + + + + + + repository.plugin.springsource.release + SpringSource Maven Repository + http://repository.springsource.com/maven/bundles/release + + + spockframework + Spock Framework + http://m2repo.spockframework.org/snapshots + + + - spring-ext - Spring External Dependencies Repository - + repository.springframework.maven.release + Spring Framework Maven Release Repository + http://maven.springframework.org/release + + + repository.springframework.maven.milestone + Spring Framework Maven Milestone Repository + http://maven.springframework.org/milestone + + + repository.springframework.maven.snapshot + Spring Framework Maven Snapshot Repository + http://maven.springframework.org/snapshot + + + spring-ext + Spring External Dependencies Repository + http://springframework.svn.sourceforge.net/svnroot/springframework/repos/repo-ext/ - - - - - - - - - org.apache.maven.plugins - maven-project-info-reports-plugin - 2.1 - - false - - - - - - - - http://www.springsource.com/spring-data - - static.springframework.org - scp://static.springframework.org/var/www/domains/springframework.org/static/htdocs/spring-data/datastore-keyvalue/snapshot-site/ - - - spring-milestone - Spring Milestone Repository - s3://maven.springframework.org/milestone - - - spring-snapshot - Spring Snapshot Repository - s3://maven.springframework.org/snapshot - - - + + + + spockframework + Spock Framework + http://m2repo.spockframework.org/snapshots + + + + + + + + org.apache.maven.plugins + maven-project-info-reports-plugin + 2.1 + + false + + + + + + + + http://www.springsource.com/spring-data + + static.springframework.org + + scp://static.springframework.org/var/www/domains/springframework.org/static/htdocs/spring-data/datastore-keyvalue/snapshot-site/ + + + + spring-milestone + Spring Milestone Repository + s3://maven.springframework.org/milestone + + + spring-snapshot + Spring Snapshot Repository + s3://maven.springframework.org/snapshot + + + \ No newline at end of file diff --git a/spring-datastore-riak/pom.xml b/spring-datastore-riak/pom.xml index 0e32db7d5..7f97d3c98 100644 --- a/spring-datastore-riak/pom.xml +++ b/spring-datastore-riak/pom.xml @@ -1,103 +1,120 @@ - 4.0.0 - - org.springframework.data - spring-datastore-keyvalue-parent - 1.0.0.BUILD-SNAPSHOT - ../spring-datastore-keyvalue-parent/pom.xml - - spring-datastore-riak - jar - Spring Datastore Riak Support - - - - - org.springframework - spring-beans - - - org.springframework - spring-tx - + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + 4.0.0 + + org.springframework.data + spring-datastore-keyvalue-parent + 1.0.0.BUILD-SNAPSHOT + ../spring-datastore-keyvalue-parent/pom.xml + + spring-datastore-riak + jar + Spring Datastore Riak Support - - - org.springframework.data - spring-datastore-keyvalue-core - + + + + org.springframework + spring-beans + + + org.springframework + spring-tx + + + org.springframework + spring-web + + + org.springframework + spring-test + - - - org.slf4j - slf4j-api - - - org.slf4j - jcl-over-slf4j - compile - - - org.slf4j - slf4j-log4j12 - runtime - - - log4j - log4j - - - javax.mail - mail - - - javax.jms - jms - - - com.sun.jdmk - jmxtools - - - com.sun.jmx - jmxri - - - runtime - - - - javax.annotation - jsr250-api - true - + + + org.springframework.data + spring-datastore-keyvalue-core + - - org.mockito - mockito-all - test - + + + org.codehaus.jackson + jackson-core-asl + + + org.codehaus.jackson + jackson-mapper-asl + - - junit - junit - + + + org.slf4j + slf4j-api + + + org.slf4j + jcl-over-slf4j + compile + + + org.slf4j + slf4j-log4j12 + runtime + + + log4j + log4j + + + javax.mail + mail + + + javax.jms + jms + + + com.sun.jdmk + jmxtools + + + com.sun.jmx + jmxri + + + runtime + - - - com.basho.riak - riak-client - 0.11.0 - + + javax.annotation + jsr250-api + true + + + + org.mockito + mockito-all + test + + + + junit + junit + + + org.spockframework + spock-spring + + + + + + + + com.springsource.bundlor + com.springsource.bundlor.maven + + + - - - - - com.springsource.bundlor - com.springsource.bundlor.maven - - - diff --git a/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/DataStoreConnectionFailureException.java b/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/DataStoreConnectionFailureException.java new file mode 100644 index 000000000..119050472 --- /dev/null +++ b/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/DataStoreConnectionFailureException.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2010 by J. Brisbin + * + * 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.datastore.riak; + +import org.springframework.dao.DataAccessResourceFailureException; + +/** + * @author J. Brisbin + */ +public class DataStoreConnectionFailureException extends DataAccessResourceFailureException { + + public DataStoreConnectionFailureException(String msg) { + super(msg); + } + + public DataStoreConnectionFailureException(String msg, Throwable cause) { + super(msg, cause); + } + +} diff --git a/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/DataStoreOperationException.java b/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/DataStoreOperationException.java new file mode 100644 index 000000000..892593a7b --- /dev/null +++ b/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/DataStoreOperationException.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2010 by J. Brisbin + * + * 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.datastore.riak; + +import org.springframework.dao.DataAccessException; + +/** + * @author J. Brisbin + */ +public class DataStoreOperationException extends DataAccessException { + + public DataStoreOperationException(String msg) { + super(msg); + } + + public DataStoreOperationException(String msg, Throwable cause) { + super(msg, cause); + } + +} diff --git a/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/convert/KeyValueStoreMetaData.java b/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/convert/KeyValueStoreMetaData.java new file mode 100644 index 000000000..1bbaa2ff7 --- /dev/null +++ b/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/convert/KeyValueStoreMetaData.java @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2010 by J. Brisbin + * + * 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.datastore.riak.convert; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +/** + * @author J. Brisbin + */ +@Retention(RetentionPolicy.RUNTIME) +public @interface KeyValueStoreMetaData { + + String family(); + + String mediaType() default "application/json"; + +} diff --git a/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/convert/RiakConversionService.java b/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/convert/RiakConversionService.java new file mode 100644 index 000000000..5cbb26a40 --- /dev/null +++ b/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/convert/RiakConversionService.java @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2010 by J. Brisbin + * + * 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.datastore.riak.convert; + +import org.springframework.core.convert.support.GenericConversionService; + +/** + * @author J. Brisbin + */ +public class RiakConversionService extends GenericConversionService{ + + public RiakConversionService() { + } +} diff --git a/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/core/AbstractAsyncOperation.java b/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/core/AbstractAsyncOperation.java new file mode 100644 index 000000000..73ee6ea9b --- /dev/null +++ b/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/core/AbstractAsyncOperation.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2010 by J. Brisbin + * + * 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.datastore.riak.core; + +import org.springframework.beans.factory.InitializingBean; +import org.springframework.util.Assert; + +import java.util.concurrent.Callable; + +/** + * @author J. Brisbin + */ +public abstract class AbstractAsyncOperation implements Callable, InitializingBean { + + protected RiakTemplate riakTemplate; + + public RiakTemplate getRiakTemplate() { + return riakTemplate; + } + + public void setRiakTemplate(RiakTemplate riakTemplate) { + this.riakTemplate = riakTemplate; + } + + public void afterPropertiesSet() throws Exception { + Assert.notNull(riakTemplate, "Must provide a configured RiakTemplate for this operation."); + } + +} diff --git a/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/core/KeyValueStoreKey.java b/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/core/KeyValueStoreKey.java new file mode 100644 index 000000000..77b27cd09 --- /dev/null +++ b/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/core/KeyValueStoreKey.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2010 by J. Brisbin + * + * 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.datastore.riak.core; + +/** + * @author J. Brisbin + */ +public class KeyValueStoreKey { + + protected Object family; + protected Object key; + + public KeyValueStoreKey() { + } + + public KeyValueStoreKey(Object family, Object key) { + this.family = family; + this.key = key; + } + + public Object getFamily() { + return family; + } + + public void setFamily(Object family) { + this.family = family; + } + + public Object getKey() { + return key; + } + + public void setKey(Object key) { + this.key = key; + } + + @Override + public String toString() { + if (null == family && null == key) { + return super.toString(); + } else { + return (null != family ? family.toString() : "") + ":" + (null != key ? key.toString() : ""); + } + } +} diff --git a/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/core/KeyValueStoreOperations.java b/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/core/KeyValueStoreOperations.java new file mode 100644 index 000000000..f27dac74b --- /dev/null +++ b/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/core/KeyValueStoreOperations.java @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2010 by J. Brisbin + * + * 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, + * WIVHOUT 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.datastore.riak.core; + +import java.util.List; +import java.util.Map; + +public interface KeyValueStoreOperations { + + // Set and Set with expiry operations + KeyValueStoreOperations set(Object key, V value); + + KeyValueStoreOperations setAsBytes(Object key, byte[] value); + + // Get operations + V get(Object key); + + byte[] getAsBytes(Object key); + + T getAsType(Object key, Class requiredType); + + // Get and Set operations + V getAndSet(Object key, V value); + + byte[] getAndSetBytes(Object key, byte[] value); + + T getAndSetAsType(Object key, Object value, Class requiredType); + + // Multi-get operations + List getValues(List keys); + + List getValues(Object... keys); + + List getValuesAsType(List keys, Class requiredType); + + List getValuesAsType(Class requiredType, Object... keys); + + // Set if non-existent operations + KeyValueStoreOperations setIfKeyNonExistent(Object key, V value); + + KeyValueStoreOperations setIfKeyNonExistentAsBytes(Object key, byte[] value); + + // Multiple key-value set + KeyValueStoreOperations setMultiple(Map keysAndValues); + + KeyValueStoreOperations setMultipleAsBytes(Map keysAndValues); + + // Multiple key-value set if non-existent + KeyValueStoreOperations setMultipleIfKeysNonExistent(Map keysAndValues); + + KeyValueStoreOperations setMultipleAsBytesIfKeysNonExistent(Map keysAndValues); + + boolean containsKey(Object keys); + + boolean deleteKeys(Object... keys); + +} diff --git a/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/core/RiakOperationCallback.java b/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/core/RiakOperationCallback.java new file mode 100644 index 000000000..a0f1d6883 --- /dev/null +++ b/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/core/RiakOperationCallback.java @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2010 by J. Brisbin + * + * 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.datastore.riak.core; + +import org.springframework.datastore.riak.DataStoreOperationException; + +/** + * @author J. Brisbin + */ +public interface RiakOperationCallback { + + public OUT execute(IN in) throws DataStoreOperationException; + +} diff --git a/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/core/RiakTemplate.java b/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/core/RiakTemplate.java new file mode 100644 index 000000000..750679119 --- /dev/null +++ b/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/core/RiakTemplate.java @@ -0,0 +1,305 @@ +/* + * Copyright (c) 2010 by J. Brisbin + * + * 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.datastore.riak.core; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.core.convert.ConversionService; +import org.springframework.core.convert.support.ConversionServiceFactory; +import org.springframework.datastore.riak.convert.KeyValueStoreMetaData; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.http.client.ClientHttpRequestFactory; +import org.springframework.util.Assert; +import org.springframework.web.client.ResourceAccessException; +import org.springframework.web.client.RestTemplate; +import org.springframework.web.client.support.RestGatewaySupport; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * @author J. Brisbin + */ +@SuppressWarnings({"unchecked"}) +public class RiakTemplate extends RestGatewaySupport implements KeyValueStoreOperations, InitializingBean { + + protected final Logger log = LoggerFactory.getLogger(getClass()); + protected ConversionService conversionService = ConversionServiceFactory.createDefaultConversionService(); + protected String defaultUri = "http://localhost:8098/riak/{bucket}/{key}"; + + public RiakTemplate() { + setRestTemplate(new RestTemplate()); + + } + + public RiakTemplate(ClientHttpRequestFactory requestFactory) { + super(requestFactory); + } + + public ConversionService getConversionService() { + return conversionService; + } + + public void setConversionService(ConversionService conversionService) { + this.conversionService = conversionService; + } + + public String getDefaultUri() { + return defaultUri; + } + + public void setDefaultUri(String defaultUri) { + this.defaultUri = defaultUri; + } + + public KeyValueStoreOperations set(Object key, V value) { + String[] bucketAndKey = getBucketAndKey(key); + if (null == bucketAndKey[0]) { + bucketAndKey[0] = value.getClass().getName(); + } + if (null == bucketAndKey[1]) { + // TODO: Handle auto-generation of key name + } + Assert.notNull(bucketAndKey[1], "Can't store an object with a NULL key."); + RestTemplate restTemplate = getRestTemplate(); + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(extractMediaType(value)); + HttpEntity entity = new HttpEntity(value, headers); + restTemplate.put(defaultUri, entity, (Object[]) bucketAndKey); + if (log.isDebugEnabled()) { + log.debug(String.format("PUT object: key=%s, value=%s", key, value)); + } + return this; + } + + public KeyValueStoreOperations setAsBytes(Object key, byte[] value) { + String[] bucketAndKey = getBucketAndKey(key); + if (null == bucketAndKey[0]) { + bucketAndKey[0] = "bytes"; + } + if (null == bucketAndKey[1]) { + // TODO: Handle auto-generation of key name + } + Assert.notNull(bucketAndKey[1], "Can't store an object with a NULL key."); + RestTemplate restTemplate = getRestTemplate(); + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_OCTET_STREAM); + HttpEntity entity = new HttpEntity(value, headers); + restTemplate.put(defaultUri, entity, (Object[]) bucketAndKey); + if (log.isDebugEnabled()) { + log.debug(String.format("PUT byte[]: key=%s", key)); + } + return this; + } + + public V get(Object key) { + String[] bucketAndKey = getBucketAndKey(key); + Assert.noNullElements(bucketAndKey, "Must specify a bucket and key to retrieve."); + RestTemplate restTemplate = getRestTemplate(); + Class targetClass; + try { + targetClass = Class.forName(bucketAndKey[0]); + } catch (ClassNotFoundException ignored) { + targetClass = Map.class; + } + if (log.isDebugEnabled()) { + log.debug(String.format("GET object: key=%s", key)); + } + return (V) restTemplate.getForObject(defaultUri, targetClass, (Object[]) bucketAndKey); + } + + public byte[] getAsBytes(Object key) { + return getAsType(key, byte[].class); + } + + public T getAsType(Object key, Class requiredType) { + String[] bucketAndKey = getBucketAndKey(key); + if (null == bucketAndKey[0]) { + bucketAndKey[0] = requiredType.getName(); + } + Assert.noNullElements(bucketAndKey, "Must specify a bucket and key to retrieve."); + RestTemplate restTemplate = getRestTemplate(); + if (log.isDebugEnabled()) { + log.debug(String.format("GET object: key=%s, type=%s", key, requiredType.getName())); + } + return (T) restTemplate.getForObject(defaultUri, requiredType, (Object[]) bucketAndKey); + } + + public V getAndSet(Object key, V value) { + V old = (V) getAsType(key, value.getClass()); + set(key, value); + return old; + } + + public byte[] getAndSetBytes(Object key, byte[] value) { + byte[] old = getAsType(key, byte[].class); + setAsBytes(key, value); + return old; + } + + public T getAndSetAsType(Object key, Object value, Class requiredType) { + T old = getAsType(key, requiredType); + set(key, value); + return old; + } + + public List getValues(List keys) { + List results = new ArrayList(); + for (Object key : keys) { + results.add(get(key)); + } + return results; + } + + public List getValues(Object... keys) { + return getValues(keys); + } + + public List getValuesAsType(List keys, Class requiredType) { + List results = new ArrayList(); + for (Object key : keys) { + results.add(getAsType(key, requiredType)); + } + return results; + } + + public List getValuesAsType(Class requiredType, Object... keys) { + List keyList = new ArrayList(keys.length); + return getValuesAsType(keyList, requiredType); + } + + public KeyValueStoreOperations setIfKeyNonExistent(Object key, V value) { + if (!containsKey(key)) { + set(key, value); + } else { + if (log.isDebugEnabled()) { + log.debug(String.format("key: %s already exists. Not adding %s", key, value)); + } + } + return this; + } + + public KeyValueStoreOperations setIfKeyNonExistentAsBytes(Object key, byte[] value) { + if (!containsKey(key)) { + setAsBytes(key, value); + } else { + if (log.isDebugEnabled()) { + log.debug(String.format("key: %s already exists. Not adding %s", key, value)); + } + } + return this; + } + + public KeyValueStoreOperations setMultiple(Map keysAndValues) { + for (Map.Entry entry : keysAndValues.entrySet()) { + set(entry.getKey(), entry.getValue()); + } + return this; + } + + public KeyValueStoreOperations setMultipleAsBytes(Map keysAndValues) { + for (Map.Entry entry : keysAndValues.entrySet()) { + setAsBytes(entry.getKey(), entry.getValue()); + } + return this; + } + + public KeyValueStoreOperations setMultipleIfKeysNonExistent(Map keysAndValues) { + for (Map.Entry entry : keysAndValues.entrySet()) { + setIfKeyNonExistent(entry.getKey(), entry.getValue()); + } + return this; + } + + public KeyValueStoreOperations setMultipleAsBytesIfKeysNonExistent(Map keysAndValues) { + for (Map.Entry entry : keysAndValues.entrySet()) { + setIfKeyNonExistentAsBytes(entry.getKey(), entry.getValue()); + } + return this; + } + + public boolean containsKey(Object key) { + String[] bucketAndKey = getBucketAndKey(key); + Assert.noNullElements(bucketAndKey, "Must specify a bucket and key to check for."); + RestTemplate restTemplate = getRestTemplate(); + HttpHeaders headers = null; + try { + headers = restTemplate.headForHeaders(defaultUri, (Object[]) bucketAndKey); + } catch (ResourceAccessException e) { + } + return (null != headers); + } + + public boolean deleteKeys(Object... keys) { + boolean deleted = false; + for (Object key : keys) { + String[] bucketAndKey = getBucketAndKey(key); + Assert.noNullElements(bucketAndKey, "Must specify a bucket and key to delete."); + RestTemplate restTemplate = getRestTemplate(); + restTemplate.delete(defaultUri, (Object[]) bucketAndKey); + deleted = (!deleted && containsKey(key) ? false : true); + } + return deleted; + } + + public void afterPropertiesSet() throws Exception { + Assert.notNull(conversionService, "Must specify a valid ConversionService."); + } + + protected String[] getBucketAndKey(Object obj) { + Object bucket = null; + Object key = null; + if (obj instanceof Map) { + Map m = (Map) obj; + bucket = m.get("bucket"); + key = m.get("key"); + } else { + String s = obj.toString(); + if (s.contains("@")) { + // This is likely the result of Object.toString() + // which returns com.mypackage.MyObject@memaddr + // Convert it using the conversion service if that's the case + s = conversionService.convert(obj, String.class); + } + if (s.contains(":")) { + String[] a = s.split(":"); + bucket = a[0]; + key = a[1]; + } else { + bucket = null; + key = s; + } + } + return new String[]{(null != bucket ? bucket.toString() : null), (null != key ? key.toString() : null)}; + } + + protected MediaType extractMediaType(Object value) { + MediaType mediaType = (value instanceof byte[] ? MediaType.APPLICATION_OCTET_STREAM : MediaType.APPLICATION_JSON); + if (value.getClass().getAnnotations().length > 0) { + KeyValueStoreMetaData meta = value.getClass().getAnnotation(KeyValueStoreMetaData.class); + if (null != meta) { + mediaType = MediaType.parseMediaType(meta.mediaType()); + } + } + return mediaType; + } + +} diff --git a/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/mapreduce/MapReduceJob.java b/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/mapreduce/MapReduceJob.java new file mode 100644 index 000000000..6f4b30a08 --- /dev/null +++ b/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/mapreduce/MapReduceJob.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2010 by J. Brisbin + * + * 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.datastore.riak.mapreduce; + +import java.util.List; + +/** + * @author J. Brisbin + */ +public interface MapReduceJob { + + MapReduceJob addInputs(List keys); + + MapReduceJob addPhase(Object phase, List operations); + + MapReduceJob setArg(Object arg); + + String toJson(); +} diff --git a/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/mapreduce/MapReduceOperations.java b/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/mapreduce/MapReduceOperations.java new file mode 100644 index 000000000..8b476c04d --- /dev/null +++ b/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/mapreduce/MapReduceOperations.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2010 by J. Brisbin + * + * 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.datastore.riak.mapreduce; + +import java.util.List; +import java.util.concurrent.Future; + +/** + * @author J. Brisbin + */ +public interface MapReduceOperations { + + List run(MapReduceJob job); + + Future> submit(MapReduceJob job); + +} diff --git a/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/mapreduce/MapReducePhase.java b/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/mapreduce/MapReducePhase.java new file mode 100644 index 000000000..7866d6f05 --- /dev/null +++ b/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/mapreduce/MapReducePhase.java @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2010 by J. Brisbin + * + * 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.datastore.riak.mapreduce; + +/** + * @author J. Brisbin + */ +public interface MapReducePhase { + + Object getMap(); + + Object getReduce(); + +} diff --git a/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/mapreduce/RiakMapReduceJob.java b/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/mapreduce/RiakMapReduceJob.java new file mode 100644 index 000000000..d69f17468 --- /dev/null +++ b/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/mapreduce/RiakMapReduceJob.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2010 by J. Brisbin + * + * 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.datastore.riak.mapreduce; + +import org.codehaus.jackson.map.ObjectMapper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author J. Brisbin + */ +public class RiakMapReduceJob implements MapReduceJob { + + protected final Logger log = LoggerFactory.getLogger(getClass()); + protected List keys = new ArrayList(); + protected List query = new ArrayList(); + protected Object arg; + protected ObjectMapper mapper = new ObjectMapper(); + + public MapReduceJob addInputs(List keys) { + + return this; + } + + public MapReduceJob addPhase(Object phase, List operations) { + return null; //To change body of implemented methods use File | Settings | File Templates. + } + + public MapReduceJob setArg(Object arg) { + this.arg = arg; + return this; + } + + public String toJson() { + + return null; //To change body of implemented methods use File | Settings | File Templates. + } +} diff --git a/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/mapreduce/RiakMapReducePhase.java b/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/mapreduce/RiakMapReducePhase.java new file mode 100644 index 000000000..a834ea953 --- /dev/null +++ b/spring-datastore-riak/src/main/java/org/springframework/datastore/riak/mapreduce/RiakMapReducePhase.java @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2010 by J. Brisbin + * + * 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.datastore.riak.mapreduce; + +/** + * @author J. Brisbin + */ +public class RiakMapReducePhase implements MapReducePhase{ + + + public Object getMap() { + return null; //To change body of implemented methods use File | Settings | File Templates. + } + + public Object getReduce() { + return null; //To change body of implemented methods use File | Settings | File Templates. + } +} diff --git a/spring-datastore-riak/src/main/resources/META-INF/spring/app-context.xml b/spring-datastore-riak/src/main/resources/META-INF/spring/app-context.xml index ca51b1a69..970f61b6d 100644 --- a/spring-datastore-riak/src/main/resources/META-INF/spring/app-context.xml +++ b/spring-datastore-riak/src/main/resources/META-INF/spring/app-context.xml @@ -1,10 +1,10 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> - Example configuration to get you started. + Example configuration to get you started. - + diff --git a/spring-datastore-riak/src/test/java/org/springframework/datastore/riak/core/RiakTemplateIntegrationTests.java b/spring-datastore-riak/src/test/java/org/springframework/datastore/riak/core/RiakTemplateIntegrationTests.java index cb3b6b8b9..dd1f1e7d8 100644 --- a/spring-datastore-riak/src/test/java/org/springframework/datastore/riak/core/RiakTemplateIntegrationTests.java +++ b/spring-datastore-riak/src/test/java/org/springframework/datastore/riak/core/RiakTemplateIntegrationTests.java @@ -16,18 +16,61 @@ package org.springframework.datastore.riak.core; -import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import java.util.LinkedHashMap; +import java.util.Map; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration({"/org/springframework/datastore/RiakTemplateTests.xml"}) +@SuppressWarnings({"unchecked"}) public class RiakTemplateIntegrationTests { - @Before - public void setUp() { - - } - - @Test - public void conversions() { - - } + @Autowired + ApplicationContext appCtx; + @Autowired + RiakTemplate riak; + + public void testSet() { + Map obj = new LinkedHashMap(); + obj.put("test", "value"); + obj.put("test2", 12); + riak.set("test:test", obj); + } + + @Test + public void testSetAsType() { + TestObject obj = new TestObject(); + riak.set("test", obj); + } + + public void testSetInferringType() { + Map obj = new LinkedHashMap(); + obj.put("test", "value"); + obj.put("test2", 12); + riak.set("test", obj); + } + + public void testGetInferringType() { + Map obj = riak.get("java.util.LinkedHashMap:test"); + assert null != obj; + assert 12 == (Integer) obj.get("test2"); + } + + @Test + public void testGetAsType() { + TestObject obj = riak.getAsType("test", TestObject.class); + assert null != obj; + } + + @Test + public void conversions() { + + } + } diff --git a/spring-datastore-riak/src/test/java/org/springframework/datastore/riak/core/RiakTemplateSpec.groovy b/spring-datastore-riak/src/test/java/org/springframework/datastore/riak/core/RiakTemplateSpec.groovy new file mode 100644 index 000000000..3a28a8363 --- /dev/null +++ b/spring-datastore-riak/src/test/java/org/springframework/datastore/riak/core/RiakTemplateSpec.groovy @@ -0,0 +1,156 @@ +/* + * Copyright (c) 2010 by J. Brisbin + * + * 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.datastore.riak.core + +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.context.ApplicationContext +import org.springframework.test.context.ContextConfiguration +import spock.lang.Specification + +/** + * @author J. Brisbin + */ +@ContextConfiguration(locations = "/org/springframework/datastore/RiakTemplateTests.xml") +class RiakTemplateSpec extends Specification { + + @Autowired + ApplicationContext appCtx + @Autowired + RiakTemplate riak + int run = 1 + + def "Test Map object with 'bucket:key' key"() { + + given: + def i = run++ + def objIn = [test: "value $i".toString(), integer: 12] + riak.set("test:test", objIn) + + when: + def objOut = riak.get("test:test") + + then: + objOut.test == "value $i" + + } + + def "Test Map object with Map key"() { + + given: + def i = run++ + def objIn = [test: "value $i".toString(), integer: 12] + riak.set([bucket: "test", key: "test"], objIn) + + when: + def objOut = riak.get([bucket: "test", key: "test"]) + + then: + objOut.test == "value $i" + + } + + def "Test custom object with 'bucket:key' key"() { + + given: + TestObject objIn = new TestObject() + riak.set("test:test", objIn) + + when: + TestObject objOut = riak.get("test:test") + + then: + objOut.test == "value" + + } + + def "Test custom object with 'ClassName:key' key"() { + + given: + TestObject objIn = new TestObject() + riak.set("test", objIn) + + when: + TestObject objOut = riak.getAsType("test", TestObject) + + then: + objOut.test == "value" + + } + + def "Test containsKey"() { + + when: + def containsKey = riak.containsKey("test:test") + + then: + true == containsKey + + } + + def "Test multiple get"() { + + when: + def objs = riak.getValues(["test:test", "${TestObject.name}:test".toString()]) + + then: + 2 == objs.size() + + } + + def "Test getAndSet with Map"() { + + given: + def i = run++ + def newObj = [test: "value $i".toString(), integer: 12] + + when: + def oldObj = riak.getAndSet("test:test", newObj) + + then: + "value" == oldObj.test + + } + + def "Test setMultipleIfKeysNonExistent with Map"() { + + given: + def i = run++ + String firstKey = "test:test$i" + String secondKey = "${TestObject.name}:test$i" + def newObj = [ + "$firstKey": [test: "value $i".toString(), integer: 12], + "$secondKey": [test: "value $i".toString(), integer: 12] + ] + + when: + def secondObj = riak.setMultipleIfKeysNonExistent(newObj).get(secondKey) + + then: + "value $i" == secondObj.test + + } + + def "Test deleteKeys"() { + + when: + def deleted = riak.deleteKeys("test:test", "${TestObject.name}:test".toString()) + + then: + true == deleted + + } + +} diff --git a/spring-datastore-riak/src/test/java/org/springframework/datastore/riak/core/TestObject.java b/spring-datastore-riak/src/test/java/org/springframework/datastore/riak/core/TestObject.java new file mode 100644 index 000000000..d435ae1f3 --- /dev/null +++ b/spring-datastore-riak/src/test/java/org/springframework/datastore/riak/core/TestObject.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2010 by J. Brisbin + * + * 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.datastore.riak.core; + +/** + * @author J. Brisbin + */ +public class TestObject { + String test = "value"; + Integer integer = 12; + + public String getTest() { + return test; + } + + public void setTest(String test) { + this.test = test; + } + + public Integer getInteger() { + return integer; + } + + public void setInteger(Integer integer) { + this.integer = integer; + } +} diff --git a/spring-datastore-riak/src/test/resources/log4j.properties b/spring-datastore-riak/src/test/resources/log4j.properties index 6d5422d74..1868ac530 100644 --- a/spring-datastore-riak/src/test/resources/log4j.properties +++ b/spring-datastore-riak/src/test/resources/log4j.properties @@ -2,11 +2,12 @@ log4j.rootCategory=INFO, stdout log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - <%m>%n +log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%n log4j.category.org.apache.activemq=ERROR log4j.category.org.springframework.batch=DEBUG log4j.category.org.springframework.transaction=INFO +log4j.category.org.springframework.datastore=DEBUG log4j.category.org.hibernate.SQL=DEBUG # for debugging datasource initialization diff --git a/spring-datastore-riak/src/test/resources/org/springframework/datastore/RiakTemplateTests.xml b/spring-datastore-riak/src/test/resources/org/springframework/datastore/RiakTemplateTests.xml new file mode 100644 index 000000000..840d44434 --- /dev/null +++ b/spring-datastore-riak/src/test/resources/org/springframework/datastore/RiakTemplateTests.xml @@ -0,0 +1,10 @@ + + + + + + + + diff --git a/spring-datastore-riak/template.mf b/spring-datastore-riak/template.mf index 473916a41..9d57c5fac 100644 --- a/spring-datastore-riak/template.mf +++ b/spring-datastore-riak/template.mf @@ -2,12 +2,16 @@ Bundle-SymbolicName: org.springframework.datastore.redis Bundle-Name: Spring Datastore Redis Support Bundle-Vendor: SpringSource Bundle-ManifestVersion: 2 -Import-Package: +Import-Package: sun.reflect;version="0";resolution:=optional -Import-Template: +Import-Template: org.springframework.beans.*;version="[3.0.0, 4.0.0)", org.springframework.core.*;version="[3.0.0, 4.0.0)", org.springframework.dao.*;version="[3.0.0, 4.0.0)", + org.springframework.http.*;version="[3.0.0, 4.0.0)", + org.springframework.http.client.*;version="[3.0.0, 4.0.0)", + org.springframework.web.*;version="[3.0.0, 4.0.0)", + org.springframework.web.client.*;version="[3.0.0, 4.0.0)", org.springframework.util.*;version="[3.0.0, 4.0.0)", org.springframework.data.core.*;version="[1.0.0, 2.0.0)", org.springframework.datastore.core.*;version="[1.0.0, 2.0.0)", @@ -15,7 +19,7 @@ Import-Template: org.springframework.datastore.persistence.*;version="[1.0.0, 2.0.0)", org.springframework.datastore.document.*;version="[1.0.0, 2.0.0)", org.aopalliance.*;version="[1.0.0, 2.0.0)";resolution:=optional, - org.apache.commons.logging.*;version="[1.1.1, 2.0.0)", + org.slf4j.*;version="[1.5.10, 2.0.0)", org.w3c.dom.*;version="0", - com.basho.riak.*;version="[0.11.0, 1.0.0)", + org.codehaus.jackson.map.*;version="[1.5.6, 1.5.6)",