diff --git a/spring-integration-voldemort/build.gradle b/spring-integration-voldemort/build.gradle index 61618f8..adc7080 100755 --- a/spring-integration-voldemort/build.gradle +++ b/spring-integration-voldemort/build.gradle @@ -1,4 +1,4 @@ -description = 'Spring Integration Voldemort Adapter' +description = 'Spring Integration Voldemort Support' buildscript { repositories { @@ -14,7 +14,7 @@ apply from: "${rootProject.projectDir}/publish-maven.gradle" apply plugin: 'eclipse' apply plugin: 'idea' -group = 'org.springframework.integration.voldemort' +group = 'org.springframework.integration' repositories { maven { url 'http://repo.springsource.org/libs-milestone' } @@ -100,6 +100,7 @@ reference { } apply plugin: 'sonar' +apply plugin: 'sonar-runner' sonar { @@ -262,5 +263,5 @@ task dist(dependsOn: assemble) { task wrapper(type: Wrapper) { description = 'Generates gradlew[.bat] scripts' - gradleVersion = '1.3' + gradleVersion = '1.5' } diff --git a/spring-integration-voldemort/gradle/wrapper/gradle-wrapper.jar b/spring-integration-voldemort/gradle/wrapper/gradle-wrapper.jar index 81dcde6..faa569a 100755 Binary files a/spring-integration-voldemort/gradle/wrapper/gradle-wrapper.jar and b/spring-integration-voldemort/gradle/wrapper/gradle-wrapper.jar differ diff --git a/spring-integration-voldemort/gradle/wrapper/gradle-wrapper.properties b/spring-integration-voldemort/gradle/wrapper/gradle-wrapper.properties index 66b16f7..8f67036 100755 --- a/spring-integration-voldemort/gradle/wrapper/gradle-wrapper.properties +++ b/spring-integration-voldemort/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Wed Sep 05 13:34:36 EDT 2012 +#Tue Apr 02 00:18:40 EDT 2013 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=http\://services.gradle.org/distributions/gradle-1.1-bin.zip +distributionUrl=http\://services.gradle.org/distributions/gradle-1.5-bin.zip diff --git a/spring-integration-voldemort/gradlew b/spring-integration-voldemort/gradlew index cf12650..91a7e26 100755 --- a/spring-integration-voldemort/gradlew +++ b/spring-integration-voldemort/gradlew @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash ############################################################################## ## @@ -61,9 +61,9 @@ while [ -h "$PRG" ] ; do fi done SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" +cd "`dirname \"$PRG\"`/" >&- APP_HOME="`pwd -P`" -cd "$SAVED" +cd "$SAVED" >&- CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar @@ -101,7 +101,7 @@ if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then warn "Could not set maximum file descriptor limit: $MAX_FD" fi else - warn "Could not query businessSystem maximum file descriptor limit: $MAX_FD_LIMIT" + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" fi fi diff --git a/spring-integration-voldemort/gradlew.bat b/spring-integration-voldemort/gradlew.bat index 8a0b282..aec9973 100755 --- a/spring-integration-voldemort/gradlew.bat +++ b/spring-integration-voldemort/gradlew.bat @@ -1,90 +1,90 @@ -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto init - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:init -@rem Get command-line arguments, handling Windowz variants - -if not "%OS%" == "Windows_NT" goto win9xME_args -if "%@eval[2+2]" == "4" goto 4NT_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* -goto execute - -:4NT_args -@rem Get arguments from the 4NT Shell from JP Software -set CMD_LINE_ARGS=%$ - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windowz variants + +if not "%OS%" == "Windows_NT" goto win9xME_args +if "%@eval[2+2]" == "4" goto 4NT_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* +goto execute + +:4NT_args +@rem Get arguments from the 4NT Shell from JP Software +set CMD_LINE_ARGS=%$ + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/spring-integration-voldemort/src/main/java/org/springframework/integration/voldemort/config/xml/VoldemortOutboundChannelAdapterParser.java b/spring-integration-voldemort/src/main/java/org/springframework/integration/voldemort/config/xml/VoldemortOutboundChannelAdapterParser.java index 3ee51aa..b3a3df4 100755 --- a/spring-integration-voldemort/src/main/java/org/springframework/integration/voldemort/config/xml/VoldemortOutboundChannelAdapterParser.java +++ b/spring-integration-voldemort/src/main/java/org/springframework/integration/voldemort/config/xml/VoldemortOutboundChannelAdapterParser.java @@ -1,65 +1,65 @@ -/* - * Copyright 2002-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.integration.voldemort.config.xml; - -import org.springframework.beans.factory.config.TypedStringValue; -import org.springframework.beans.factory.support.AbstractBeanDefinition; -import org.springframework.beans.factory.support.BeanDefinitionBuilder; -import org.springframework.beans.factory.support.RootBeanDefinition; -import org.springframework.beans.factory.xml.ParserContext; -import org.springframework.integration.config.ExpressionFactoryBean; -import org.springframework.integration.config.xml.AbstractOutboundChannelAdapterParser; -import org.springframework.integration.config.xml.IntegrationNamespaceUtils; -import org.springframework.integration.voldemort.outbound.VoldemortStoringMessageHandler; -import org.w3c.dom.Element; - -/** - * Parses Voldemort outbound adapter XML definition. - * - * @author Lukasz Antoniak - * @since 1.0 - */ -public class VoldemortOutboundChannelAdapterParser extends AbstractOutboundChannelAdapterParser { - /** - * Produces "int-voldemort:outbound-channel-adapter" bean definition. - *

- * {@inheritDoc} - */ - @Override - protected AbstractBeanDefinition parseConsumer(Element element, ParserContext parserContext) { - final BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition( VoldemortStoringMessageHandler.class ); - VoldemortParserUtils.processCommonAttributes( element, builder ); - final boolean hasKey = element.hasAttribute( VoldemortParserUtils.STORE_KEY ); - final boolean hasKeyExpression = element.hasAttribute( VoldemortParserUtils.STORE_KEY_EXPRESSION ); - if ( hasKey && hasKeyExpression ) { - parserContext.getReaderContext().error( "At most one of '" + VoldemortParserUtils.STORE_KEY - + "' or '" + VoldemortParserUtils.STORE_KEY_EXPRESSION + "' is allowed.", element ); - } - if ( hasKey ) { - builder.addPropertyValue( - VoldemortParserUtils.KEY_PROPERTY, - new TypedStringValue( element.getAttribute( VoldemortParserUtils.STORE_KEY ) ) - ); - } - if ( hasKeyExpression ) { - RootBeanDefinition expressionDef = new RootBeanDefinition( ExpressionFactoryBean.class ); - expressionDef.getConstructorArgumentValues().addGenericArgumentValue( element.getAttribute( VoldemortParserUtils.STORE_KEY_EXPRESSION ) ); - builder.addPropertyValue( VoldemortParserUtils.KEY_EXPRESSION_PROPERTY, expressionDef ); - } - IntegrationNamespaceUtils.setValueIfAttributeDefined( builder, element, VoldemortParserUtils.PERSIST_MODE ); - return builder.getBeanDefinition(); - } -} +/* + * Copyright 2002-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.integration.voldemort.config.xml; + +import org.springframework.beans.factory.config.TypedStringValue; +import org.springframework.beans.factory.support.AbstractBeanDefinition; +import org.springframework.beans.factory.support.BeanDefinitionBuilder; +import org.springframework.beans.factory.support.RootBeanDefinition; +import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.integration.config.ExpressionFactoryBean; +import org.springframework.integration.config.xml.AbstractOutboundChannelAdapterParser; +import org.springframework.integration.config.xml.IntegrationNamespaceUtils; +import org.springframework.integration.voldemort.outbound.VoldemortStoringMessageHandler; +import org.w3c.dom.Element; + +/** + * Parses Voldemort outbound adapter XML definition. + * + * @author Lukasz Antoniak + * @since 1.0 + */ +public class VoldemortOutboundChannelAdapterParser extends AbstractOutboundChannelAdapterParser { + /** + * Produces "int-voldemort:outbound-channel-adapter" bean definition. + *

+ * {@inheritDoc} + */ + @Override + protected AbstractBeanDefinition parseConsumer(Element element, ParserContext parserContext) { + final BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition( VoldemortStoringMessageHandler.class ); + VoldemortParserUtils.processCommonAttributes( element, builder ); + final boolean hasKey = element.hasAttribute( VoldemortParserUtils.STORE_KEY ); + final boolean hasKeyExpression = element.hasAttribute( VoldemortParserUtils.STORE_KEY_EXPRESSION ); + if ( hasKey && hasKeyExpression ) { + parserContext.getReaderContext().error( "At most one of '" + VoldemortParserUtils.STORE_KEY + + "' or '" + VoldemortParserUtils.STORE_KEY_EXPRESSION + "' is allowed.", element ); + } + if ( hasKey ) { + builder.addPropertyValue( + VoldemortParserUtils.KEY_PROPERTY, + new TypedStringValue( element.getAttribute( VoldemortParserUtils.STORE_KEY ) ) + ); + } + if ( hasKeyExpression ) { + RootBeanDefinition expressionDef = new RootBeanDefinition( ExpressionFactoryBean.class ); + expressionDef.getConstructorArgumentValues().addGenericArgumentValue( element.getAttribute( VoldemortParserUtils.STORE_KEY_EXPRESSION ) ); + builder.addPropertyValue( VoldemortParserUtils.KEY_EXPRESSION_PROPERTY, expressionDef ); + } + IntegrationNamespaceUtils.setValueIfAttributeDefined( builder, element, VoldemortParserUtils.PERSIST_MODE ); + return builder.getBeanDefinition(); + } +} diff --git a/spring-integration-voldemort/src/main/java/org/springframework/integration/voldemort/config/xml/VoldemortParserUtils.java b/spring-integration-voldemort/src/main/java/org/springframework/integration/voldemort/config/xml/VoldemortParserUtils.java index 1762115..d416b0e 100755 --- a/spring-integration-voldemort/src/main/java/org/springframework/integration/voldemort/config/xml/VoldemortParserUtils.java +++ b/spring-integration-voldemort/src/main/java/org/springframework/integration/voldemort/config/xml/VoldemortParserUtils.java @@ -24,7 +24,7 @@ import org.w3c.dom.Element; * @author Lukasz Antoniak * @since 1.0 */ -abstract class VoldemortParserUtils { +public final class VoldemortParserUtils { static final String STORE_CLIENT = "store-client"; static final String PERSIST_MODE = "persist-mode"; static final String SEARCH_KEY = "search-key"; @@ -37,6 +37,11 @@ abstract class VoldemortParserUtils { static final String KEY_PROPERTY = "key"; static final String KEY_EXPRESSION_PROPERTY = "keyExpression"; + /** Prevent instantiation. */ + private VoldemortParserUtils() { + throw new AssertionError(); + } + /** * Handles "store-client" and "message-converter" attributes. */ diff --git a/spring-integration-voldemort/src/main/java/org/springframework/integration/voldemort/inbound/VoldemortMessageSource.java b/spring-integration-voldemort/src/main/java/org/springframework/integration/voldemort/inbound/VoldemortMessageSource.java index d6524e3..2c046c5 100644 --- a/spring-integration-voldemort/src/main/java/org/springframework/integration/voldemort/inbound/VoldemortMessageSource.java +++ b/spring-integration-voldemort/src/main/java/org/springframework/integration/voldemort/inbound/VoldemortMessageSource.java @@ -32,7 +32,9 @@ import voldemort.versioning.Versioned; * @author Lukasz Antoniak * @since 1.0 */ -public class VoldemortMessageSource extends IntegrationObjectSupport implements MessageSource { +public class VoldemortMessageSource extends IntegrationObjectSupport + implements MessageSource { + private final StoreClient client; /** @@ -65,15 +67,15 @@ public class VoldemortMessageSource extends IntegrationObjectSupport implements @Override @SuppressWarnings("unchecked") - public Message receive() { + public Message receive() { final Object key = keyExpression.getValue( evaluationContext, Object.class ); - final Versioned value = client.get( key ); + final Versioned value = client.get( key ); if ( value != null ) { if ( deleteAfterPoll ) { client.delete( key ); } return MessageBuilder.withPayload( extractValue ? value.getValue() : value ) - .setHeader( VoldemortHeaders.KEY, key ).build(); + .setHeader(VoldemortHeaders.KEY, key ).build(); } return null; } diff --git a/spring-integration-voldemort/src/main/java/org/springframework/integration/voldemort/outbound/VoldemortStoringMessageHandler.java b/spring-integration-voldemort/src/main/java/org/springframework/integration/voldemort/outbound/VoldemortStoringMessageHandler.java index 8704746..edf38e7 100755 --- a/spring-integration-voldemort/src/main/java/org/springframework/integration/voldemort/outbound/VoldemortStoringMessageHandler.java +++ b/spring-integration-voldemort/src/main/java/org/springframework/integration/voldemort/outbound/VoldemortStoringMessageHandler.java @@ -1,112 +1,112 @@ -/* - * Copyright 2002-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.integration.voldemort.outbound; - -import org.springframework.expression.Expression; -import org.springframework.expression.common.LiteralExpression; -import org.springframework.expression.spel.standard.SpelExpressionParser; -import org.springframework.expression.spel.support.StandardEvaluationContext; -import org.springframework.integration.Message; -import org.springframework.integration.expression.ExpressionUtils; -import org.springframework.integration.handler.AbstractMessageHandler; -import org.springframework.integration.voldemort.support.PersistMode; -import org.springframework.integration.voldemort.support.VoldemortHeaders; -import voldemort.client.StoreClient; - -/** - * Voldemort outbound adapter implementation. - * - * @author Lukasz Antoniak - * @since 1.0 - */ -public class VoldemortStoringMessageHandler extends AbstractMessageHandler { - private final StoreClient client; - - private volatile StandardEvaluationContext evaluationContext; - private volatile Expression keyExpression = new SpelExpressionParser().parseExpression( "headers." + VoldemortHeaders.KEY ); - - private volatile PersistMode persistMode = PersistMode.PUT; - - /** - * Creates new message sender. - * - * @param client Voldemort store client. - */ - public VoldemortStoringMessageHandler(StoreClient client) { - this.client = client; - } - - @Override - protected void onInit() throws Exception { - super.onInit(); - if ( getBeanFactory() != null ) { - evaluationContext = ExpressionUtils.createStandardEvaluationContext( getBeanFactory() ); - } - else { - evaluationContext = ExpressionUtils.createStandardEvaluationContext(); - } - } - - @Override - @SuppressWarnings("unchecked") - protected void handleMessageInternal(Message message) throws Exception { - final Object key = keyExpression.getValue( evaluationContext, message, Object.class ); - switch ( determinePersistMode( message ) ) { - case PUT: - client.put( key, message.getPayload() ); - break; - case DELETE: - client.delete( key ); - break; - } - } - - /** - * Computes desired persist mode for a given message. Default output adapter's configuration - * can be overridden with {@link VoldemortHeaders#PERSIST_MODE} message header which supports - * direct or text representation of {@link PersistMode} enumeration. - * - * @param message Spring Integration message. - * @return Persist mode. - */ - private PersistMode determinePersistMode(Message message) { - final Object confValue = message.getHeaders().get( VoldemortHeaders.PERSIST_MODE ); - if ( confValue instanceof PersistMode ) { - return (PersistMode) confValue; - } - else if ( confValue instanceof String ) { - return PersistMode.valueOf( (String) confValue ); - } - return persistMode; - } - - @Override - public String getComponentType() { - return "voldemort:outbound-channel-adapter"; - } - - public void setKey(String key) { - setKeyExpression( new LiteralExpression( key ) ); - } - - public void setKeyExpression(Expression keyExpression) { - this.keyExpression = keyExpression; - } - - public void setPersistMode(PersistMode persistMode) { - this.persistMode = persistMode; - } -} +/* + * Copyright 2002-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.integration.voldemort.outbound; + +import org.springframework.expression.Expression; +import org.springframework.expression.common.LiteralExpression; +import org.springframework.expression.spel.standard.SpelExpressionParser; +import org.springframework.expression.spel.support.StandardEvaluationContext; +import org.springframework.integration.Message; +import org.springframework.integration.expression.ExpressionUtils; +import org.springframework.integration.handler.AbstractMessageHandler; +import org.springframework.integration.voldemort.support.PersistMode; +import org.springframework.integration.voldemort.support.VoldemortHeaders; +import voldemort.client.StoreClient; + +/** + * Voldemort outbound adapter implementation. + * + * @author Lukasz Antoniak + * @since 1.0 + */ +public class VoldemortStoringMessageHandler extends AbstractMessageHandler { + private final StoreClient client; + + private volatile StandardEvaluationContext evaluationContext; + private volatile Expression keyExpression = new SpelExpressionParser().parseExpression( "headers." + VoldemortHeaders.KEY ); + + private volatile PersistMode persistMode = PersistMode.PUT; + + /** + * Creates new message sender. + * + * @param client Voldemort store client. + */ + public VoldemortStoringMessageHandler(StoreClient client) { + this.client = client; + } + + @Override + protected void onInit() throws Exception { + super.onInit(); + if ( getBeanFactory() != null ) { + evaluationContext = ExpressionUtils.createStandardEvaluationContext( getBeanFactory() ); + } + else { + evaluationContext = ExpressionUtils.createStandardEvaluationContext(); + } + } + + @Override + @SuppressWarnings("unchecked") + protected void handleMessageInternal(Message message) throws Exception { + final Object key = keyExpression.getValue( evaluationContext, message, Object.class ); + switch ( determinePersistMode( message ) ) { + case PUT: + client.put( key, message.getPayload() ); + break; + case DELETE: + client.delete( key ); + break; + } + } + + /** + * Computes desired persist mode for a given message. Default output adapter's configuration + * can be overridden with {@link VoldemortHeaders#PERSIST_MODE} message header which supports + * direct or text representation of {@link PersistMode} enumeration. + * + * @param message Spring Integration message. + * @return Persist mode. + */ + private PersistMode determinePersistMode(Message message) { + final Object confValue = message.getHeaders().get( VoldemortHeaders.PERSIST_MODE ); + if ( confValue instanceof PersistMode ) { + return (PersistMode) confValue; + } + else if ( confValue instanceof String ) { + return PersistMode.valueOf( (String) confValue ); + } + return persistMode; + } + + @Override + public String getComponentType() { + return "voldemort:outbound-channel-adapter"; + } + + public void setKey(String key) { + setKeyExpression( new LiteralExpression( key ) ); + } + + public void setKeyExpression(Expression keyExpression) { + this.keyExpression = keyExpression; + } + + public void setPersistMode(PersistMode persistMode) { + this.persistMode = persistMode; + } +} diff --git a/spring-integration-voldemort/src/main/java/org/springframework/integration/voldemort/store/VoldemortMessageStore.java b/spring-integration-voldemort/src/main/java/org/springframework/integration/voldemort/store/VoldemortMessageStore.java index 6caf424..c141b06 100644 --- a/spring-integration-voldemort/src/main/java/org/springframework/integration/voldemort/store/VoldemortMessageStore.java +++ b/spring-integration-voldemort/src/main/java/org/springframework/integration/voldemort/store/VoldemortMessageStore.java @@ -45,14 +45,14 @@ public class VoldemortMessageStore extends AbstractKeyValueMessageStore implemen /** * Key under which message store tracks all currently saved message identifiers. */ - protected final static String MESSAGE_KEY_LIST = "MESSAGE_KEY_LIST"; + protected static final String MESSAGE_KEY_LIST = "MESSAGE_KEY_LIST"; /** * Key under which message store tracks all currently saved message group identifiers. */ - protected final static String MESSAGE_GROUP_KEY_LIST = "MESSAGE_GROUP_KEY_LIST"; + protected static final String MESSAGE_GROUP_KEY_LIST = "MESSAGE_GROUP_KEY_LIST"; - private final static LockRegistry LOCK_REGISTRY = new DefaultLockRegistry(); + private static final LockRegistry LOCK_REGISTRY = new DefaultLockRegistry(); private final StoreClient client; @@ -99,7 +99,7 @@ public class VoldemortMessageStore extends AbstractKeyValueMessageStore implemen } } catch ( SerializationException e ) { - throw new IllegalArgumentException( "Voldemort failed to serialize message with id: " + id + "." ); + throw new IllegalArgumentException( "Voldemort failed to serialize message with id: " + id + ".", e ); } finally { messageLock.unlock(); @@ -181,7 +181,7 @@ public class VoldemortMessageStore extends AbstractKeyValueMessageStore implemen /** * Voldemort update action that adds given key to the list of currently saved identifiers. */ - private static class AddKeyUpdateAction extends UpdateAction { + private static final class AddKeyUpdateAction extends UpdateAction { private final Object id; private final String keyListKey; @@ -208,7 +208,7 @@ public class VoldemortMessageStore extends AbstractKeyValueMessageStore implemen /** * Voldemort update action that removes given key from the list of currently saved identifiers. */ - private static class RemoveKeyUpdateAction extends UpdateAction { + private static final class RemoveKeyUpdateAction extends UpdateAction { private final Object id; private final String keyListKey; diff --git a/spring-integration-voldemort/src/main/java/org/springframework/integration/voldemort/support/VoldemortHeaders.java b/spring-integration-voldemort/src/main/java/org/springframework/integration/voldemort/support/VoldemortHeaders.java index ca92796..f973f20 100644 --- a/spring-integration-voldemort/src/main/java/org/springframework/integration/voldemort/support/VoldemortHeaders.java +++ b/spring-integration-voldemort/src/main/java/org/springframework/integration/voldemort/support/VoldemortHeaders.java @@ -27,7 +27,7 @@ public abstract class VoldemortHeaders { /** * Header representing key under which message payload should be stored. */ - public static final String KEY = PREFIX + "_key"; + public static final String KEY = PREFIX + "key"; /** * Overrides default output adapter's persist mode for a given message. diff --git a/spring-integration-voldemort/src/main/resources/org/springframework/integration/config/xml/spring-integration-voldemort-1.0.xsd b/spring-integration-voldemort/src/main/resources/org/springframework/integration/config/xml/spring-integration-voldemort-1.0.xsd index 9b053db..0d329f0 100755 --- a/spring-integration-voldemort/src/main/resources/org/springframework/integration/config/xml/spring-integration-voldemort-1.0.xsd +++ b/spring-integration-voldemort/src/main/resources/org/springframework/integration/config/xml/spring-integration-voldemort-1.0.xsd @@ -1,187 +1,196 @@ + xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:beans="http://www.springframework.org/schema/beans" + xmlns:tool="http://www.springframework.org/schema/tool" + xmlns:integration="http://www.springframework.org/schema/integration" + targetNamespace="http://www.springframework.org/schema/integration/voldemort" + elementFormDefault="qualified" attributeFormDefault="unqualified"> - - - + + + - - + - + - - - - Defines an Outbound Channel Adapter that writes messages to - Voldemort key-value store. - - - - - - - - Specifies the key for Voldemort store. If an expression - is needed, use 'store-key-expression' attribute. - Both options are mutually exclusive. - - - - - - - Spring Expression Language statement used to determine - desired entry key in Voldemort store. - Default expression equals 'headers.voldemort_key'. - This attribute is mutually exclusive with 'store-key' attribute. - - - - - - - Defines default persist mode for outbound-channel-adapter. - By default values are added or updated in the underlying - Voldemort database. Hereby behavior can be overridden using - VoldemortHeaders.PERSIST_MODE message header. - - - - - - - - - - Specifies the order for invocation when this endpoint is connected as a - subscriber to SubscribableChannel. - - - - - + + + + Defines an Outbound Channel Adapter that writes messages to + Voldemort key-value store. + + + + + + + + Specifies the key for the Voldemort store. If an expression + is needed, use the 'store-key-expression' attribute. + Both options are mutually exclusive. + + + + + + + Spring Expression Language statement used to determine + the desired entry key into the Voldemort store. + Default expression equals 'headers.voldemort_key'. + This attribute is mutually exclusive with the 'store-key' + attribute. + + + + + + + Defines the default persist mode for the outbound-channel-adapter. + Available modes are: - - - - Defines an Inbound Channel Adapter that reads records from Voldemort - key-value store. - - - - - - - - - - - String key that is being searched. - This attribute is mutually exclusive - with 'search-key-expression' attribute. - - - - - - - Spring Expression Language statement that returns - desired entry key. - This attribute is mutually exclusive with 'search-key' attribute. - - - - - - - Indicates whether returned object should be removed - from Voldemort database after polling into Spring - Integration channel. - - - - - - - - - - Flag controlling value extraction from Voldemort's - Versioned object. - - - - - - - - + - PUT + - DELETE - - - - Common configuration for Voldemort adapters. - - - - - - Identifies the underlying Spring bean definition. - - - - - - - - Reference to a MessageChannel that will be utilized to - "receive from" or "send to" messages depending on the - adapter type (e.g. inbound or outbound). - - - - - - - - - - - - Native Voldemort store client. - - - - - - - - - - - Flag to indicate that the component should start automatically - on startup (default true). - - - - - - - + By default values are added or updated in the underlying + Voldemort database (PUT). The specified behavior can be + overridden using the VoldemortHeaders.PERSIST_MODE message header. + + + + + + + + + + Specifies the order for invocation when this endpoint is + connected as a subscriber to SubscribableChannel. + + + + + - - - - - - + + + + Defines an Inbound Channel Adapter that reads records from + the Voldemort key-value store. + + + + + + + + + + + String key that is being searched for. + This attribute is mutually exclusive + with the 'search-key-expression' attribute. + + + + + + + Spring Expression Language (SpEL) statement that + returns the desired entry key. + + This attribute is mutually exclusive with the + 'search-key' attribute. + + + + + + + Indicates whether returned objects should be removed + from the Voldemort database after polling. Defaults to + 'false'. + + + + + + + + + + Flag controlling the value extraction from Voldemort's + Versioned object. Defaults to 'true'. + + + + + + + + + + + + + Common configuration for Voldemort adapters. + + + + + + Identifies the underlying Spring bean definition. + + + + + + + Reference to a MessageChannel that will be utilized to + "receive from" or "send to" messages depending on the + adapter type (e.g. inbound or outbound). + + + + + + + + + + + + Native Voldemort store client. Needs to be an implementation + of 'voldemort.client.StoreClient'. + + + + + + + + + + + + Flag indicating that the component should start automatically + on startup (default is 'true'). + + + + + + + + + + + + + + diff --git a/spring-integration-voldemort/src/test/java/org/springframework/integration/voldemort/test/BaseFunctionalTestCase.java b/spring-integration-voldemort/src/test/java/org/springframework/integration/voldemort/test/BaseFunctionalTestCase.java index 4e30167..15b573e 100755 --- a/spring-integration-voldemort/src/test/java/org/springframework/integration/voldemort/test/BaseFunctionalTestCase.java +++ b/spring-integration-voldemort/src/test/java/org/springframework/integration/voldemort/test/BaseFunctionalTestCase.java @@ -1,101 +1,101 @@ -/* - * Copyright 2002-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.integration.voldemort.test; - -import java.io.File; -import java.util.Properties; - -import org.apache.commons.io.FileUtils; -import org.junit.After; -import org.junit.Before; -import voldemort.server.VoldemortConfig; -import voldemort.server.VoldemortServer; - -/** - * Base class for functional test cases. Handles embedded Voldemort server startup and shutdown. - * - * @author Lukasz Antoniak - * @since 1.0 - */ -public abstract class BaseFunctionalTestCase { - protected VoldemortServer server = null; - - /** - * Starts Voldemort embedded server. - */ - @Before - public void setUp() throws Exception { - final VoldemortConfig config = configureServer(); - server = new VoldemortServer( config ); - server.start(); - } - - /** - * Stops Voldemort embedded server. - */ - @After - public void tearDown() throws Exception { - if ( server != null && server.isStarted() ) { - server.stop(); - } - } - - /** - * Review cluster.xml and stores.xml configuration files. - * - * @return Voldemort embedded server configuration. - */ - protected VoldemortConfig configureServer() throws Exception { - final File voldemortHome = new File( System.getProperty( "java.io.tmpdir" ), "voldemort" ); - FileUtils.deleteDirectory( voldemortHome ); - - final Properties properties = new Properties(); - properties.put( "node.id", "0" ); - properties.put( "voldemort.home", voldemortHome.getAbsolutePath() ); - addConfigOptions( properties ); - final VoldemortConfig config = new VoldemortConfig( properties ); - - final File metadata = new File( config.getMetadataDirectory() ); - FileUtils.forceMkdir( metadata ); - - FileUtils.copyFileToDirectory( getClusterConfiguration(), metadata ); - FileUtils.copyFileToDirectory( getStoreConfiguration(), metadata ); - - return config; - } - - /** - * @return Voldemort cluster configuration descriptor. - */ - protected File getClusterConfiguration() { - return new File( "src/test/resources/cluster.xml" ); - } - - /** - * @return Voldemort store configuration descriptor. - */ - protected File getStoreConfiguration() { - return new File( "src/test/resources/stores.xml" ); - } - - /** - * Subclasses may want to setup specific server configuration parameters. - * - * @param properties Voldemort server configuration properties. - */ - protected void addConfigOptions(Properties properties) { - } -} +/* + * Copyright 2002-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.integration.voldemort.test; + +import java.io.File; +import java.util.Properties; + +import org.apache.commons.io.FileUtils; +import org.junit.After; +import org.junit.Before; +import voldemort.server.VoldemortConfig; +import voldemort.server.VoldemortServer; + +/** + * Base class for functional test cases. Handles embedded Voldemort server startup and shutdown. + * + * @author Lukasz Antoniak + * @since 1.0 + */ +public abstract class BaseFunctionalTestCase { + protected VoldemortServer server = null; + + /** + * Starts Voldemort embedded server. + */ + @Before + public void setUp() throws Exception { + final VoldemortConfig config = configureServer(); + server = new VoldemortServer( config ); + server.start(); + } + + /** + * Stops Voldemort embedded server. + */ + @After + public void tearDown() throws Exception { + if ( server != null && server.isStarted() ) { + server.stop(); + } + } + + /** + * Review cluster.xml and stores.xml configuration files. + * + * @return Voldemort embedded server configuration. + */ + protected VoldemortConfig configureServer() throws Exception { + final File voldemortHome = new File( System.getProperty( "java.io.tmpdir" ), "voldemort" ); + FileUtils.deleteDirectory( voldemortHome ); + + final Properties properties = new Properties(); + properties.put( "node.id", "0" ); + properties.put( "voldemort.home", voldemortHome.getAbsolutePath() ); + addConfigOptions( properties ); + final VoldemortConfig config = new VoldemortConfig( properties ); + + final File metadata = new File( config.getMetadataDirectory() ); + FileUtils.forceMkdir( metadata ); + + FileUtils.copyFileToDirectory( getClusterConfiguration(), metadata ); + FileUtils.copyFileToDirectory( getStoreConfiguration(), metadata ); + + return config; + } + + /** + * @return Voldemort cluster configuration descriptor. + */ + protected File getClusterConfiguration() { + return new File( "src/test/resources/cluster.xml" ); + } + + /** + * @return Voldemort store configuration descriptor. + */ + protected File getStoreConfiguration() { + return new File( "src/test/resources/stores.xml" ); + } + + /** + * Subclasses may want to setup specific server configuration parameters. + * + * @param properties Voldemort server configuration properties. + */ + protected void addConfigOptions(Properties properties) { + } +} diff --git a/spring-integration-voldemort/src/test/java/org/springframework/integration/voldemort/test/domain/Car.java b/spring-integration-voldemort/src/test/java/org/springframework/integration/voldemort/test/domain/Car.java index 0b81119..e5fd953 100644 --- a/spring-integration-voldemort/src/test/java/org/springframework/integration/voldemort/test/domain/Car.java +++ b/spring-integration-voldemort/src/test/java/org/springframework/integration/voldemort/test/domain/Car.java @@ -18,7 +18,7 @@ package org.springframework.integration.voldemort.test.domain; import java.io.Serializable; /** - * Sample object with composite key persisted in Voldemort database. + * Sample object with composite key persisted to Voldemort database. * * @author Lukasz Antoniak * @since 1.0 diff --git a/spring-integration-voldemort/src/test/java/org/springframework/integration/voldemort/test/domain/Person.java b/spring-integration-voldemort/src/test/java/org/springframework/integration/voldemort/test/domain/Person.java index 071279d..6b9227a 100755 --- a/spring-integration-voldemort/src/test/java/org/springframework/integration/voldemort/test/domain/Person.java +++ b/spring-integration-voldemort/src/test/java/org/springframework/integration/voldemort/test/domain/Person.java @@ -1,89 +1,89 @@ -/* - * Copyright 2002-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.integration.voldemort.test.domain; - -import java.io.Serializable; - -/** - * Sample object persisted in Voldemort database. - * - * @author Lukasz Antoniak - * @since 1.0 - */ -public class Person implements Serializable { - private static final long serialVersionUID = -9092199331950213292L; - - private String id; - private String firstName; - private String lastName; - - public Person(String id, String firstName, String lastName) { - this.id = id; - this.firstName = firstName; - this.lastName = lastName; - } - - @Override - public boolean equals(Object o) { - if ( this == o ) return true; - if ( !( o instanceof Person ) ) return false; - - Person person = (Person) o; - - if ( id != null ? !id.equals( person.id ) : person.id != null ) return false; - if ( firstName != null ? !firstName.equals( person.firstName ) : person.firstName != null ) return false; - if ( lastName != null ? !lastName.equals( person.lastName ) : person.lastName != null ) return false; - - return true; - } - - @Override - public int hashCode() { - int result = id != null ? id.hashCode() : 0; - result = 31 * result + ( firstName != null ? firstName.hashCode() : 0 ); - result = 31 * result + ( lastName != null ? lastName.hashCode() : 0 ); - return result; - } - - @Override - public String toString() { - return "Person(id = " + id + ", firstName = " + firstName + ", lastName = " + lastName + ")"; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getFirstName() { - return firstName; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public String getLastName() { - return lastName; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - } -} +/* + * Copyright 2002-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.integration.voldemort.test.domain; + +import java.io.Serializable; + +/** + * Sample object persisted in Voldemort database. + * + * @author Lukasz Antoniak + * @since 1.0 + */ +public class Person implements Serializable { + private static final long serialVersionUID = -9092199331950213292L; + + private String id; + private String firstName; + private String lastName; + + public Person(String id, String firstName, String lastName) { + this.id = id; + this.firstName = firstName; + this.lastName = lastName; + } + + @Override + public boolean equals(Object o) { + if ( this == o ) return true; + if ( !( o instanceof Person ) ) return false; + + Person person = (Person) o; + + if ( id != null ? !id.equals( person.id ) : person.id != null ) return false; + if ( firstName != null ? !firstName.equals( person.firstName ) : person.firstName != null ) return false; + if ( lastName != null ? !lastName.equals( person.lastName ) : person.lastName != null ) return false; + + return true; + } + + @Override + public int hashCode() { + int result = id != null ? id.hashCode() : 0; + result = 31 * result + ( firstName != null ? firstName.hashCode() : 0 ); + result = 31 * result + ( lastName != null ? lastName.hashCode() : 0 ); + return result; + } + + @Override + public String toString() { + return "Person(id = " + id + ", firstName = " + firstName + ", lastName = " + lastName + ")"; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } +} diff --git a/spring-integration-voldemort/src/test/java/org/springframework/integration/voldemort/test/outbound/VoldemortOutboundAdapterTest.java b/spring-integration-voldemort/src/test/java/org/springframework/integration/voldemort/test/outbound/VoldemortOutboundAdapterTest.java index 588cba8..1275863 100755 --- a/spring-integration-voldemort/src/test/java/org/springframework/integration/voldemort/test/outbound/VoldemortOutboundAdapterTest.java +++ b/spring-integration-voldemort/src/test/java/org/springframework/integration/voldemort/test/outbound/VoldemortOutboundAdapterTest.java @@ -1,177 +1,177 @@ -/* - * Copyright 2002-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.integration.voldemort.test.outbound; - -import junit.framework.Assert; -import org.junit.Test; -import org.springframework.context.support.ClassPathXmlApplicationContext; -import org.springframework.integration.Message; -import org.springframework.integration.MessageChannel; -import org.springframework.integration.MessageDeliveryException; -import org.springframework.integration.support.MessageBuilder; -import org.springframework.integration.voldemort.support.PersistMode; -import org.springframework.integration.voldemort.support.VoldemortHeaders; -import org.springframework.integration.voldemort.test.BaseFunctionalTestCase; -import org.springframework.integration.voldemort.test.domain.Person; -import voldemort.client.StoreClient; -import voldemort.versioning.Versioned; - -/** - * Voldemort basic outbound adapter tests. - * - * @author Lukasz Antoniak - * @since 1.0 - */ -@SuppressWarnings("unchecked") -public class VoldemortOutboundAdapterTest extends BaseFunctionalTestCase { - @Test - public void testPutObject() { - final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "VoldemortOutboundAdapterTest-context.xml", getClass() ); - final StoreClient storeClient = context.getBean( "storeClient", StoreClient.class ); - final MessageChannel voldemortOutboundPutChannel = context.getBean( "voldemortOutboundPutChannel", MessageChannel.class ); - - // given - final Person lukasz = new Person( "1", "Lukasz", "Antoniak" ); - - // when - final Message message = MessageBuilder.withPayload( lukasz ).setHeader( VoldemortHeaders.KEY, lukasz.getId() ).build(); - voldemortOutboundPutChannel.send( message ); - - // then - final Versioned found = storeClient.get( lukasz.getId() ); - Assert.assertEquals( lukasz, found.getValue() ); - - context.close(); - } - - @Test - public void testPutObjectsConstantKey() { - final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "VoldemortOutboundAdapterTest-context.xml", getClass() ); - final StoreClient storeClient = context.getBean( "storeClient", StoreClient.class ); - final MessageChannel voldemortOutboundChannel = context.getBean( "voldemortOutboundPutConstantKeyChannel", MessageChannel.class ); - - // given - final Person lukasz = new Person( "1", "Lukasz", "Antoniak" ); - - // when - final Message firstMessage = MessageBuilder.withPayload( lukasz ).build(); - voldemortOutboundChannel.send( firstMessage ); - - // then - Assert.assertEquals( lukasz, storeClient.get( "constant-key" ).getValue() ); - - // given - final Person tomasz = new Person( "2", "Tomasz", "Antoniak" ); - - // when - final Message secondMessage = MessageBuilder.withPayload( tomasz ).build(); - voldemortOutboundChannel.send( secondMessage ); - - // then - Assert.assertEquals( tomasz, storeClient.get( "constant-key" ).getValue() ); - - context.close(); - } - - @Test - public void testDeleteObject() { - final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "VoldemortOutboundAdapterTest-context.xml", getClass() ); - final StoreClient storeClient = context.getBean( "storeClient", StoreClient.class ); - final MessageChannel voldemortOutboundDeleteChannel = context.getBean( "voldemortOutboundDeleteChannel", MessageChannel.class ); - - // given - final Person lukasz = new Person( "1", "Lukasz", "Antoniak" ); - storeClient.put( lukasz.getId(), lukasz ); - - // when - final Message message = MessageBuilder.withPayload( lukasz ).build(); - voldemortOutboundDeleteChannel.send( message ); - - // then - final Versioned found = storeClient.get( lukasz.getId() ); - Assert.assertNull( found ); - - context.close(); - } - - @Test - public void testOverridePersistMode() { - final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "VoldemortOutboundAdapterTest-context.xml", getClass() ); - final StoreClient storeClient = context.getBean( "storeClient", StoreClient.class ); - final MessageChannel voldemortOutboundDeleteChannel = context.getBean( "voldemortOutboundDeleteChannel", MessageChannel.class ); - - // given - final Person lukasz = new Person( "1", "Lukasz", "Antoniak" ); - - // when - // Overriding output adapter's persist mode. - final Message message = MessageBuilder.withPayload( lukasz ) - .setHeader( VoldemortHeaders.PERSIST_MODE, PersistMode.PUT ).build(); - voldemortOutboundDeleteChannel.send( message ); - - // then - final Versioned found = storeClient.get( lukasz.getId() ); - Assert.assertEquals( lukasz, found.getValue() ); - - context.close(); - } - - @Test - public void testStoppedAdapter() { - final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "VoldemortOutboundAdapterTest-context.xml", getClass() ); - final MessageChannel voldemortStoppedChannel = context.getBean( "voldemortStoppedChannel", MessageChannel.class ); - - // given - final Person lukasz = new Person( "1", "Lukasz", "Antoniak" ); - - // when - final Message message = MessageBuilder.withPayload( lukasz ).build(); - try { - voldemortStoppedChannel.send( message ); - } - catch ( MessageDeliveryException e ) { - return; - } - finally { - context.close(); - } - - Assert.fail(); - } - - @Test - public void testOrder() { - final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "VoldemortOutboundAdapterTest-context.xml", getClass() ); - final StoreClient storeClient = context.getBean( "storeClient", StoreClient.class ); - final MessageUpdatingServiceActivator messageUpdater = context.getBean( "messageUpdater", MessageUpdatingServiceActivator.class ); - final MessageChannel voldemortOrderChannel = context.getBean( "voldemortOrderChannel", MessageChannel.class ); - - // given - final Person lukasz = new Person( "lukasz", "Lukasz", "Antoniak" ); - final Person copy = new Person( "lukasz", "Lukasz", "Antoniak" ); - - // when - final Message message = MessageBuilder.withPayload( lukasz ).build(); - voldemortOrderChannel.send( message ); - - // then - messageUpdater.updatePerson( copy ); - final Versioned found = storeClient.get( lukasz.getId() ); - Assert.assertEquals( copy, found.getValue() ); - - context.close(); - } -} +/* + * Copyright 2002-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.integration.voldemort.test.outbound; + +import junit.framework.Assert; +import org.junit.Test; +import org.springframework.context.support.ClassPathXmlApplicationContext; +import org.springframework.integration.Message; +import org.springframework.integration.MessageChannel; +import org.springframework.integration.MessageDeliveryException; +import org.springframework.integration.support.MessageBuilder; +import org.springframework.integration.voldemort.support.PersistMode; +import org.springframework.integration.voldemort.support.VoldemortHeaders; +import org.springframework.integration.voldemort.test.BaseFunctionalTestCase; +import org.springframework.integration.voldemort.test.domain.Person; +import voldemort.client.StoreClient; +import voldemort.versioning.Versioned; + +/** + * Voldemort basic outbound adapter tests. + * + * @author Lukasz Antoniak + * @since 1.0 + */ +@SuppressWarnings("unchecked") +public class VoldemortOutboundAdapterTest extends BaseFunctionalTestCase { + @Test + public void testPutObject() { + final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "VoldemortOutboundAdapterTest-context.xml", getClass() ); + final StoreClient storeClient = context.getBean( "storeClient", StoreClient.class ); + final MessageChannel voldemortOutboundPutChannel = context.getBean( "voldemortOutboundPutChannel", MessageChannel.class ); + + // given + final Person lukasz = new Person( "1", "Lukasz", "Antoniak" ); + + // when + final Message message = MessageBuilder.withPayload( lukasz ).setHeader( VoldemortHeaders.KEY, lukasz.getId() ).build(); + voldemortOutboundPutChannel.send( message ); + + // then + final Versioned found = storeClient.get( lukasz.getId() ); + Assert.assertEquals( lukasz, found.getValue() ); + + context.close(); + } + + @Test + public void testPutObjectsConstantKey() { + final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "VoldemortOutboundAdapterTest-context.xml", getClass() ); + final StoreClient storeClient = context.getBean( "storeClient", StoreClient.class ); + final MessageChannel voldemortOutboundChannel = context.getBean( "voldemortOutboundPutConstantKeyChannel", MessageChannel.class ); + + // given + final Person lukasz = new Person( "1", "Lukasz", "Antoniak" ); + + // when + final Message firstMessage = MessageBuilder.withPayload( lukasz ).build(); + voldemortOutboundChannel.send( firstMessage ); + + // then + Assert.assertEquals( lukasz, storeClient.get( "constant-key" ).getValue() ); + + // given + final Person tomasz = new Person( "2", "Tomasz", "Antoniak" ); + + // when + final Message secondMessage = MessageBuilder.withPayload( tomasz ).build(); + voldemortOutboundChannel.send( secondMessage ); + + // then + Assert.assertEquals( tomasz, storeClient.get( "constant-key" ).getValue() ); + + context.close(); + } + + @Test + public void testDeleteObject() { + final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "VoldemortOutboundAdapterTest-context.xml", getClass() ); + final StoreClient storeClient = context.getBean( "storeClient", StoreClient.class ); + final MessageChannel voldemortOutboundDeleteChannel = context.getBean( "voldemortOutboundDeleteChannel", MessageChannel.class ); + + // given + final Person lukasz = new Person( "1", "Lukasz", "Antoniak" ); + storeClient.put( lukasz.getId(), lukasz ); + + // when + final Message message = MessageBuilder.withPayload( lukasz ).build(); + voldemortOutboundDeleteChannel.send( message ); + + // then + final Versioned found = storeClient.get( lukasz.getId() ); + Assert.assertNull( found ); + + context.close(); + } + + @Test + public void testOverridePersistMode() { + final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "VoldemortOutboundAdapterTest-context.xml", getClass() ); + final StoreClient storeClient = context.getBean( "storeClient", StoreClient.class ); + final MessageChannel voldemortOutboundDeleteChannel = context.getBean( "voldemortOutboundDeleteChannel", MessageChannel.class ); + + // given + final Person lukasz = new Person( "1", "Lukasz", "Antoniak" ); + + // when + // Overriding output adapter's persist mode. + final Message message = MessageBuilder.withPayload( lukasz ) + .setHeader( VoldemortHeaders.PERSIST_MODE, PersistMode.PUT ).build(); + voldemortOutboundDeleteChannel.send( message ); + + // then + final Versioned found = storeClient.get( lukasz.getId() ); + Assert.assertEquals( lukasz, found.getValue() ); + + context.close(); + } + + @Test + public void testStoppedAdapter() { + final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "VoldemortOutboundAdapterTest-context.xml", getClass() ); + final MessageChannel voldemortStoppedChannel = context.getBean( "voldemortStoppedChannel", MessageChannel.class ); + + // given + final Person lukasz = new Person( "1", "Lukasz", "Antoniak" ); + + // when + final Message message = MessageBuilder.withPayload( lukasz ).build(); + try { + voldemortStoppedChannel.send( message ); + } + catch ( MessageDeliveryException e ) { + return; + } + finally { + context.close(); + } + + Assert.fail(); + } + + @Test + public void testOrder() { + final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "VoldemortOutboundAdapterTest-context.xml", getClass() ); + final StoreClient storeClient = context.getBean( "storeClient", StoreClient.class ); + final MessageUpdatingServiceActivator messageUpdater = context.getBean( "messageUpdater", MessageUpdatingServiceActivator.class ); + final MessageChannel voldemortOrderChannel = context.getBean( "voldemortOrderChannel", MessageChannel.class ); + + // given + final Person lukasz = new Person( "lukasz", "Lukasz", "Antoniak" ); + final Person copy = new Person( "lukasz", "Lukasz", "Antoniak" ); + + // when + final Message message = MessageBuilder.withPayload( lukasz ).build(); + voldemortOrderChannel.send( message ); + + // then + messageUpdater.updatePerson( copy ); + final Versioned found = storeClient.get( lukasz.getId() ); + Assert.assertEquals( copy, found.getValue() ); + + context.close(); + } +} diff --git a/spring-integration-voldemort/src/test/java/org/springframework/integration/voldemort/test/store/BaseStoreFunctionalTestCase.java b/spring-integration-voldemort/src/test/java/org/springframework/integration/voldemort/test/store/BaseStoreFunctionalTestCase.java index 8fc8641..8843123 100644 --- a/spring-integration-voldemort/src/test/java/org/springframework/integration/voldemort/test/store/BaseStoreFunctionalTestCase.java +++ b/spring-integration-voldemort/src/test/java/org/springframework/integration/voldemort/test/store/BaseStoreFunctionalTestCase.java @@ -1,3 +1,18 @@ +/* + * Copyright 2002-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.integration.voldemort.test.store; import java.io.File; diff --git a/spring-integration-voldemort/src/test/java/org/springframework/integration/voldemort/test/store/VoldemortMessageStoreAggregationTest.java b/spring-integration-voldemort/src/test/java/org/springframework/integration/voldemort/test/store/VoldemortMessageStoreAggregationTest.java index c38016e..4bb8bd1 100644 --- a/spring-integration-voldemort/src/test/java/org/springframework/integration/voldemort/test/store/VoldemortMessageStoreAggregationTest.java +++ b/spring-integration-voldemort/src/test/java/org/springframework/integration/voldemort/test/store/VoldemortMessageStoreAggregationTest.java @@ -32,7 +32,6 @@ import org.springframework.integration.voldemort.test.BaseFunctionalTestCase; * @author Lukasz Antoniak * @since 1.0 */ -@SuppressWarnings("unchecked") public class VoldemortMessageStoreAggregationTest extends BaseFunctionalTestCase { @Override protected File getStoreConfiguration() { diff --git a/spring-integration-voldemort/src/test/resources/cluster.xml b/spring-integration-voldemort/src/test/resources/cluster.xml index 69f4a64..eb4c3eb 100755 --- a/spring-integration-voldemort/src/test/resources/cluster.xml +++ b/spring-integration-voldemort/src/test/resources/cluster.xml @@ -1,12 +1,12 @@ - - - test-cluster - - 0 - localhost - 8080 - 6666 - 6667 - 0, 1 - - \ No newline at end of file + + + test-cluster + + 0 + localhost + 8080 + 6666 + 6667 + 0, 1 + + diff --git a/spring-integration-voldemort/src/test/resources/org/springframework/integration/voldemort/test/common-test-context.xml b/spring-integration-voldemort/src/test/resources/org/springframework/integration/voldemort/test/common-test-context.xml index 2995ee6..7d7d056 100755 --- a/spring-integration-voldemort/src/test/resources/org/springframework/integration/voldemort/test/common-test-context.xml +++ b/spring-integration-voldemort/src/test/resources/org/springframework/integration/voldemort/test/common-test-context.xml @@ -1,16 +1,17 @@ - - - - - - - - - - - - - - \ No newline at end of file + + + + + + + + + + + + + + + diff --git a/spring-integration-voldemort/src/test/resources/org/springframework/integration/voldemort/test/inbound/ObjectKeyTest-context.xml b/spring-integration-voldemort/src/test/resources/org/springframework/integration/voldemort/test/inbound/ObjectKeyTest-context.xml index bda59a3..17361ab 100644 --- a/spring-integration-voldemort/src/test/resources/org/springframework/integration/voldemort/test/inbound/ObjectKeyTest-context.xml +++ b/spring-integration-voldemort/src/test/resources/org/springframework/integration/voldemort/test/inbound/ObjectKeyTest-context.xml @@ -1,25 +1,26 @@ - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:int="http://www.springframework.org/schema/integration" + xmlns:int-voldemort="http://www.springframework.org/schema/integration/voldemort" + xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd + http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd + http://www.springframework.org/schema/integration/voldemort http://www.springframework.org/schema/integration/voldemort/spring-integration-voldemort.xsd"> - - - + - - - + + + - + + + - - - - \ No newline at end of file + + + + + + diff --git a/spring-integration-voldemort/src/test/resources/org/springframework/integration/voldemort/test/inbound/VoldemortInboundAdapterTest-context.xml b/spring-integration-voldemort/src/test/resources/org/springframework/integration/voldemort/test/inbound/VoldemortInboundAdapterTest-context.xml index f5ac708..cc84a4c 100644 --- a/spring-integration-voldemort/src/test/resources/org/springframework/integration/voldemort/test/inbound/VoldemortInboundAdapterTest-context.xml +++ b/spring-integration-voldemort/src/test/resources/org/springframework/integration/voldemort/test/inbound/VoldemortInboundAdapterTest-context.xml @@ -1,30 +1,31 @@ - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:int="http://www.springframework.org/schema/integration" + xmlns:int-voldemort="http://www.springframework.org/schema/integration/voldemort" + xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd + http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd + http://www.springframework.org/schema/integration/voldemort http://www.springframework.org/schema/integration/voldemort/spring-integration-voldemort.xsd"> - - - + - - - + + + - - - + + + - - - - \ No newline at end of file + + + + + + + + diff --git a/spring-integration-voldemort/src/test/resources/org/springframework/integration/voldemort/test/outbound/ObjectKeyTest-context.xml b/spring-integration-voldemort/src/test/resources/org/springframework/integration/voldemort/test/outbound/ObjectKeyTest-context.xml index a0e7eb6..ac6020e 100644 --- a/spring-integration-voldemort/src/test/resources/org/springframework/integration/voldemort/test/outbound/ObjectKeyTest-context.xml +++ b/spring-integration-voldemort/src/test/resources/org/springframework/integration/voldemort/test/outbound/ObjectKeyTest-context.xml @@ -1,19 +1,20 @@ - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:int="http://www.springframework.org/schema/integration" + xmlns:int-voldemort="http://www.springframework.org/schema/integration/voldemort" + xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd + http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd + http://www.springframework.org/schema/integration/voldemort http://www.springframework.org/schema/integration/voldemort/spring-integration-voldemort.xsd"> - - - + - + + + - - \ No newline at end of file + + + + diff --git a/spring-integration-voldemort/src/test/resources/org/springframework/integration/voldemort/test/outbound/VoldemortOutboundAdapterTest-context.xml b/spring-integration-voldemort/src/test/resources/org/springframework/integration/voldemort/test/outbound/VoldemortOutboundAdapterTest-context.xml index 1c0b337..55524fa 100755 --- a/spring-integration-voldemort/src/test/resources/org/springframework/integration/voldemort/test/outbound/VoldemortOutboundAdapterTest-context.xml +++ b/spring-integration-voldemort/src/test/resources/org/springframework/integration/voldemort/test/outbound/VoldemortOutboundAdapterTest-context.xml @@ -1,42 +1,43 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/spring-integration-voldemort/src/test/resources/org/springframework/integration/voldemort/test/store/VoldemortMessageStoreAggregationTest-context.xml b/spring-integration-voldemort/src/test/resources/org/springframework/integration/voldemort/test/store/VoldemortMessageStoreAggregationTest-context.xml index c861068..9598434 100644 --- a/spring-integration-voldemort/src/test/resources/org/springframework/integration/voldemort/test/store/VoldemortMessageStoreAggregationTest-context.xml +++ b/spring-integration-voldemort/src/test/resources/org/springframework/integration/voldemort/test/store/VoldemortMessageStoreAggregationTest-context.xml @@ -1,14 +1,15 @@ - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:int="http://www.springframework.org/schema/integration" + xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd + http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd"> - + - - - - \ No newline at end of file + + + + + + diff --git a/spring-integration-voldemort/src/test/resources/org/springframework/integration/voldemort/test/store/store-test-context.xml b/spring-integration-voldemort/src/test/resources/org/springframework/integration/voldemort/test/store/store-test-context.xml index 83f1ba9..b595472 100644 --- a/spring-integration-voldemort/src/test/resources/org/springframework/integration/voldemort/test/store/store-test-context.xml +++ b/spring-integration-voldemort/src/test/resources/org/springframework/integration/voldemort/test/store/store-test-context.xml @@ -1,25 +1,26 @@ - - - + xsi:schemaLocation=" + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> - - - + + + - - - + + + - - - + + + - - - - \ No newline at end of file + + + + + + + + diff --git a/spring-integration-voldemort/src/test/resources/org/springframework/integration/voldemort/test/store/stores.xml b/spring-integration-voldemort/src/test/resources/org/springframework/integration/voldemort/test/store/stores.xml index afa6fbf..90b80ec 100644 --- a/spring-integration-voldemort/src/test/resources/org/springframework/integration/voldemort/test/store/stores.xml +++ b/spring-integration-voldemort/src/test/resources/org/springframework/integration/voldemort/test/store/stores.xml @@ -1,19 +1,19 @@ - - test-message-store - lukasz.antoniak@gmail.com - bdb - client - 1 - 1 - 1 - - string - UTF-8 - - - java-serialization - - - \ No newline at end of file + + test-message-store + lukasz.antoniak@gmail.com + bdb + client + 1 + 1 + 1 + + string + UTF-8 + + + java-serialization + + + diff --git a/spring-integration-voldemort/src/test/resources/stores.xml b/spring-integration-voldemort/src/test/resources/stores.xml index 013c15f..404ead9 100755 --- a/spring-integration-voldemort/src/test/resources/stores.xml +++ b/spring-integration-voldemort/src/test/resources/stores.xml @@ -1,34 +1,34 @@ - - - - test-store - lukasz.antoniak@gmail.com - bdb - client - 1 - 1 - 1 - - string - UTF-8 - - - java-serialization - - - - test-object-store - lukasz.antoniak@gmail.com - bdb - client - 1 - 1 - 1 - - java-serialization - - - java-serialization - - - \ No newline at end of file + + + + test-store + lukasz.antoniak@gmail.com + bdb + client + 1 + 1 + 1 + + string + UTF-8 + + + java-serialization + + + + test-object-store + lukasz.antoniak@gmail.com + bdb + client + 1 + 1 + 1 + + java-serialization + + + java-serialization + + +