From 23cb654b181ed366b4333fa4026c5d6abfdc0b6b Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Mon, 29 Aug 2016 10:55:14 +0200 Subject: [PATCH] DATACASS-217 - Add support for LZ4 compression. Original pull request: #82. --- .../config/CassandraCqlClusterFactoryBean.java | 3 +++ .../cassandra/config/CompressionType.java | 5 +++-- .../CassandraCqlClusterFactoryBeanUnitTests.java | 16 ++++++++++++++++ ...CreatingXmlConfigIntegrationTests-context.xml | 2 +- 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/spring-cql/src/main/java/org/springframework/cassandra/config/CassandraCqlClusterFactoryBean.java b/spring-cql/src/main/java/org/springframework/cassandra/config/CassandraCqlClusterFactoryBean.java index d50ae8c0a..14da7ecdb 100644 --- a/spring-cql/src/main/java/org/springframework/cassandra/config/CassandraCqlClusterFactoryBean.java +++ b/spring-cql/src/main/java/org/springframework/cassandra/config/CassandraCqlClusterFactoryBean.java @@ -701,11 +701,14 @@ public class CassandraCqlClusterFactoryBean implements FactoryBean, Ini } private static Compression convertCompressionType(CompressionType type) { + switch (type) { case NONE: return Compression.NONE; case SNAPPY: return Compression.SNAPPY; + case LZ4: + return Compression.LZ4; } throw new IllegalArgumentException(String.format("Unknown compression type [%s]", type)); diff --git a/spring-cql/src/main/java/org/springframework/cassandra/config/CompressionType.java b/spring-cql/src/main/java/org/springframework/cassandra/config/CompressionType.java index b244a87ac..cbdb76546 100644 --- a/spring-cql/src/main/java/org/springframework/cassandra/config/CompressionType.java +++ b/spring-cql/src/main/java/org/springframework/cassandra/config/CompressionType.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2014 the original author or authors. + * Copyright 2013-2016 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. @@ -19,7 +19,8 @@ package org.springframework.cassandra.config; * Simple enumeration for the various compression types. * * @author Alex Shvid + * @author Mark Paluch */ public enum CompressionType { - NONE, SNAPPY; + NONE, SNAPPY, LZ4 } diff --git a/spring-cql/src/test/java/org/springframework/cassandra/config/CassandraCqlClusterFactoryBeanUnitTests.java b/spring-cql/src/test/java/org/springframework/cassandra/config/CassandraCqlClusterFactoryBeanUnitTests.java index 1745f92d6..580cedbf5 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/config/CassandraCqlClusterFactoryBeanUnitTests.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/config/CassandraCqlClusterFactoryBeanUnitTests.java @@ -101,6 +101,22 @@ public class CassandraCqlClusterFactoryBeanUnitTests { assertThat(getConfiguration(bean).getProtocolOptions().getCompression(), is(Compression.SNAPPY)); } + /** + * @see DATACASS-217 + * @throws Exception + */ + @Test + public void shouldSetLZ4CompressionType() throws Exception { + + CompressionType compressionType = CompressionType.LZ4; + + CassandraCqlClusterFactoryBean bean = new CassandraCqlClusterFactoryBean(); + bean.setCompressionType(compressionType); + bean.afterPropertiesSet(); + + assertThat(getConfiguration(bean).getProtocolOptions().getCompression(), is(Compression.LZ4)); + } + /** * @see DATACASS-226 * @throws Exception diff --git a/spring-cql/src/test/resources/org/springframework/cassandra/test/integration/config/xml/FullySpecifiedKeyspaceCreatingXmlConfigIntegrationTests-context.xml b/spring-cql/src/test/resources/org/springframework/cassandra/test/integration/config/xml/FullySpecifiedKeyspaceCreatingXmlConfigIntegrationTests-context.xml index 047b3587f..05662131e 100644 --- a/spring-cql/src/test/resources/org/springframework/cassandra/test/integration/config/xml/FullySpecifiedKeyspaceCreatingXmlConfigIntegrationTests-context.xml +++ b/spring-cql/src/test/resources/org/springframework/cassandra/test/integration/config/xml/FullySpecifiedKeyspaceCreatingXmlConfigIntegrationTests-context.xml @@ -10,7 +10,7 @@ - +