Updated Branches: refs/heads/trunk 9ec7b808a -> fc8b76f79
http://git-wip-us.apache.org/repos/asf/cassandra/blob/fc8b76f7/src/java/org/apache/cassandra/type/SetSerializer.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/type/SetSerializer.java b/src/java/org/apache/cassandra/type/SetSerializer.java deleted file mode 100644 index f60acb4..0000000 --- a/src/java/org/apache/cassandra/type/SetSerializer.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.cassandra.type; - -import java.nio.BufferUnderflowException; -import java.nio.ByteBuffer; -import java.util.*; - -public class SetSerializer<T> extends CollectionSerializer<Set<T>> -{ - // interning instances - private static final Map<AbstractSerializer<?>, SetSerializer> instances = new HashMap<AbstractSerializer<?>, SetSerializer>(); - - public final AbstractSerializer<T> elements; - - public static synchronized <T> SetSerializer<T> getInstance(AbstractSerializer<T> elements) - { - SetSerializer<T> t = instances.get(elements); - if (t == null) - { - t = new SetSerializer<T>(elements); - instances.put(elements, t); - } - return t; - } - - private SetSerializer(AbstractSerializer<T> elements) - { - this.elements = elements; - } - - public Set<T> serialize(ByteBuffer bytes) - { - try - { - ByteBuffer input = bytes.duplicate(); - int n = getUnsignedShort(input); - Set<T> l = new LinkedHashSet<T>(n); - for (int i = 0; i < n; i++) - { - int s = getUnsignedShort(input); - byte[] data = new byte[s]; - input.get(data); - ByteBuffer databb = ByteBuffer.wrap(data); - elements.validate(databb); - l.add(elements.serialize(databb)); - } - return l; - } - catch (BufferUnderflowException e) - { - throw new MarshalException("Not enough bytes to read a list"); - } - } - - /** - * Layout is: {@code <n><s_1><b_1>...<s_n><b_n> } - * where: - * n is the number of elements - * s_i is the number of bytes composing the ith element - * b_i is the s_i bytes composing the ith element - */ - public ByteBuffer deserialize(Set<T> value) - { - List<ByteBuffer> bbs = new ArrayList<ByteBuffer>(value.size()); - int size = 0; - for (T elt : value) - { - ByteBuffer bb = elements.deserialize(elt); - bbs.add(bb); - size += 2 + bb.remaining(); - } - return pack(bbs, value.size(), size); - } - - public String toString(Set<T> value) - { - StringBuffer sb = new StringBuffer(); - boolean isFirst = true; - for (T element : value) - { - if (isFirst) - { - isFirst = false; - } - else - { - sb.append("; "); - } - sb.append(elements.toString(element)); - } - return sb.toString(); - } - - public Class<Set<T>> getType() - { - return (Class) Set.class; - } -} http://git-wip-us.apache.org/repos/asf/cassandra/blob/fc8b76f7/src/java/org/apache/cassandra/type/TimeUUIDSerializer.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/type/TimeUUIDSerializer.java b/src/java/org/apache/cassandra/type/TimeUUIDSerializer.java deleted file mode 100644 index b767012..0000000 --- a/src/java/org/apache/cassandra/type/TimeUUIDSerializer.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.cassandra.type; - -import java.nio.ByteBuffer; - -public class TimeUUIDSerializer extends UUIDSerializer -{ - @Override - public void validate(ByteBuffer bytes) throws MarshalException - { - super.validate(bytes); - - // Super class only validates the Time UUID - ByteBuffer slice = bytes.slice(); - // version is bits 4-7 of byte 6. - if (bytes.remaining() > 0) - { - slice.position(6); - if ((slice.get() & 0xf0) != 0x10) - throw new MarshalException("Invalid version for TimeUUID type."); - } - } -} http://git-wip-us.apache.org/repos/asf/cassandra/blob/fc8b76f7/src/java/org/apache/cassandra/type/TimestampSerializer.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/type/TimestampSerializer.java b/src/java/org/apache/cassandra/type/TimestampSerializer.java deleted file mode 100644 index 84042e1..0000000 --- a/src/java/org/apache/cassandra/type/TimestampSerializer.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.cassandra.type; - -import org.apache.cassandra.utils.ByteBufferUtil; - -import java.nio.ByteBuffer; -import java.text.SimpleDateFormat; -import java.util.Date; - -public class TimestampSerializer extends AbstractSerializer<Date> -{ - public static final String[] iso8601Patterns = new String[] { - "yyyy-MM-dd HH:mm", - "yyyy-MM-dd HH:mm:ss", - "yyyy-MM-dd HH:mmZ", - "yyyy-MM-dd HH:mm:ssZ", - "yyyy-MM-dd'T'HH:mm", - "yyyy-MM-dd'T'HH:mmZ", - "yyyy-MM-dd'T'HH:mm:ss", - "yyyy-MM-dd'T'HH:mm:ssZ", - "yyyy-MM-dd", - "yyyy-MM-ddZ" - }; - - static final String DEFAULT_FORMAT = iso8601Patterns[3]; - - static final ThreadLocal<SimpleDateFormat> FORMATTER = new ThreadLocal<SimpleDateFormat>() - { - protected SimpleDateFormat initialValue() - { - return new SimpleDateFormat(DEFAULT_FORMAT); - } - }; - - public static final TimestampSerializer instance = new TimestampSerializer(); - - @Override - public Date serialize(ByteBuffer bytes) - { - return bytes.remaining() > 0 - ? new Date(ByteBufferUtil.toLong(bytes)) - : null; - } - - @Override - public ByteBuffer deserialize(Date value) - { - return (value == null) - ? ByteBufferUtil.EMPTY_BYTE_BUFFER - : ByteBufferUtil.bytes(value.getTime()); - } - - @Override - public void validate(ByteBuffer bytes) throws MarshalException - { - if (bytes.remaining() != 8 && bytes.remaining() != 0) - throw new MarshalException(String.format("Expected 8 or 0 byte long for date (%d)", bytes.remaining())); - } - - @Override - public String getString(ByteBuffer bytes) - { - if (bytes.remaining() == 0) - { - return ""; - } - if (bytes.remaining() != 8) - { - throw new MarshalException("A date is exactly 8 bytes (stored as a long): " + bytes.remaining()); - } - - // uses ISO-8601 formatted string - return FORMATTER.get().format(new Date(ByteBufferUtil.toLong(bytes))); - } - - @Override - public String toString(Date value) - { - return FORMATTER.get().format(value); - } - - @Override - public Class<Date> getType() - { - return Date.class; - } -} http://git-wip-us.apache.org/repos/asf/cassandra/blob/fc8b76f7/src/java/org/apache/cassandra/type/UTF8Serializer.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/type/UTF8Serializer.java b/src/java/org/apache/cassandra/type/UTF8Serializer.java deleted file mode 100644 index 4c44788..0000000 --- a/src/java/org/apache/cassandra/type/UTF8Serializer.java +++ /dev/null @@ -1,193 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.cassandra.type; - -import org.apache.cassandra.utils.ByteBufferUtil; - -import java.nio.ByteBuffer; -import java.nio.charset.CharacterCodingException; -import java.nio.charset.Charset; - -public class UTF8Serializer extends AbstractSerializer<String> -{ - public static final UTF8Serializer instance = new UTF8Serializer(); - private static final Charset UTF_8 = Charset.forName("UTF-8"); - - @Override - public String serialize(ByteBuffer bytes) - { - return getString(bytes); - } - - @Override - public ByteBuffer deserialize(String value) - { - return ByteBufferUtil.bytes(value, UTF_8); - } - - @Override - public void validate(ByteBuffer bytes) throws MarshalException - { - if (!UTF8Validator.validate(bytes)) - throw new MarshalException("String didn't validate."); - } - - static class UTF8Validator - { - enum State { - START, - TWO, - TWO_80, - THREE_a0bf, - THREE_80bf_1, - THREE_80bf_2, - FOUR_90bf, - FOUR_80bf_3, - }; - - // since we're not converting to java strings, we don't need to worry about converting to surrogates. - // buf has already been sliced/duplicated. - static boolean validate(ByteBuffer buf) - { - buf = buf.slice(); - int b = 0; - State state = State.START; - while (buf.remaining() > 0) - { - b = buf.get(); - switch (state) - { - case START: - if (b >= 0) - { - // ascii, state stays start. - if (b > 127) - return false; - } - else if ((b >> 5) == -2) - { - // validate first byte of 2-byte char, 0xc2-0xdf - if (b == (byte) 0xc0) - // speical case: modified utf8 null is 0xc080. - state = State.TWO_80; - else if ((b & 0x1e) == 0) - return false; - state = State.TWO; - } - else if ((b >> 4) == -2) - { - // 3 bytes. first byte will be 0xe0 or 0xe1-0xef. handling of second byte will differ. - // so 0xe0,0xa0-0xbf,0x80-0xbf or 0xe1-0xef,0x80-0xbf,0x80-0xbf. - if (b == (byte)0xe0) - state = State.THREE_a0bf; - else - state = State.THREE_80bf_2; - break; - } - else if ((b >> 3) == -2) - { - // 4 bytes. this is where the fun starts. - if (b == (byte)0xf0) - // 0xf0, 0x90-0xbf, 0x80-0xbf, 0x80-0xbf - state = State.FOUR_90bf; - else if (b == (byte)0xf4) - // 0xf4, 0x80-0xbf, 0x80-0xbf, 0x80-0xbf - state = State.FOUR_80bf_3; - else - // 0xf1-0xf3, 0x80-0xbf, 0x80-0xbf, 0x80-0xbf - state = State.FOUR_80bf_3; - break; - } - else - return false; // malformed. - break; - case TWO: - // validate second byte of 2-byte char, 0x80-0xbf - if ((b & 0xc0) != 0x80) - return false; - state = State.START; - break; - case TWO_80: - if (b != (byte)0x80) - return false; - state = State.START; - break; - case THREE_a0bf: - if ((b & 0xe0) == 0x80) - return false; - state = State.THREE_80bf_1; - break; - case THREE_80bf_1: - // expecting 0x80-0xbf - if ((b & 0xc0) != 0x80) - return false; - state = State.START; - break; - case THREE_80bf_2: - // expecting 0x80-bf and then another of the same. - if ((b & 0xc0) != 0x80) - return false; - state = State.THREE_80bf_1; - break; - case FOUR_90bf: - // expecting 0x90-bf. 2nd byte of 4byte sequence. after that it should degrade to 80-bf,80-bf (like 3byte seq). - if ((b & 0x30) == 0) - return false; - state = State.THREE_80bf_2; - break; - case FOUR_80bf_3: - // expecting 0x80-bf 3 times. degenerates to THREE_80bf_2. - if ((b & 0xc0) != 0x80) - return false; - state = State.THREE_80bf_2; - break; - default: - return false; // invalid state. - } - } - // if state != start, we've got underflow. that's an error. - return state == State.START; - } - } - - @Override - public String getString(ByteBuffer bytes) - { - try - { - return ByteBufferUtil.string(bytes, UTF_8); - } - catch (CharacterCodingException e) - { - throw new MarshalException("Invalid ascii bytes " + ByteBufferUtil.bytesToHex(bytes)); - } - } - - @Override - public String toString(String value) - { - return value; - } - - @Override - public Class<String> getType() - { - return String.class; - } -} http://git-wip-us.apache.org/repos/asf/cassandra/blob/fc8b76f7/src/java/org/apache/cassandra/type/UUIDSerializer.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/type/UUIDSerializer.java b/src/java/org/apache/cassandra/type/UUIDSerializer.java deleted file mode 100644 index 07b86b6..0000000 --- a/src/java/org/apache/cassandra/type/UUIDSerializer.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.cassandra.type; - -import org.apache.cassandra.utils.UUIDGen; - -import java.nio.ByteBuffer; -import java.util.UUID; - -public class UUIDSerializer extends AbstractSerializer<UUID> -{ - public static final UUIDSerializer instance = new UUIDSerializer(); - - @Override - public UUID serialize(ByteBuffer bytes) - { - return UUIDGen.getUUID(bytes); - } - - @Override - public ByteBuffer deserialize(UUID value) - { - return ByteBuffer.wrap(UUIDGen.decompose(value)); - } - - @Override - public void validate(ByteBuffer bytes) throws MarshalException - { - if (bytes.remaining() != 16 && bytes.remaining() != 0) - throw new MarshalException(String.format("UUID should be 16 or 0 bytes (%d)", bytes.remaining())); - // not sure what the version should be for this. - } - - @Override - public String getString(ByteBuffer bytes) - { - if (bytes.remaining() == 0) - { - return ""; - } - if (bytes.remaining() != 16) - { - throw new MarshalException("UUIDs must be exactly 16 bytes"); - } - UUID uuid = UUIDGen.getUUID(bytes); - return uuid.toString(); - } - - @Override - public String toString(UUID value) - { - return value.toString(); - } - - @Override - public Class<UUID> getType() - { - return UUID.class; - } -} http://git-wip-us.apache.org/repos/asf/cassandra/blob/fc8b76f7/test/unit/org/apache/cassandra/cql/jdbc/JdbcDecimalTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/cql/jdbc/JdbcDecimalTest.java b/test/unit/org/apache/cassandra/cql/jdbc/JdbcDecimalTest.java index 90a8200..cb88ae8 100644 --- a/test/unit/org/apache/cassandra/cql/jdbc/JdbcDecimalTest.java +++ b/test/unit/org/apache/cassandra/cql/jdbc/JdbcDecimalTest.java @@ -21,7 +21,7 @@ package org.apache.cassandra.cql.jdbc; import java.math.BigDecimal; import java.nio.ByteBuffer; -import org.apache.cassandra.type.DecimalSerializer; +import org.apache.cassandra.serializers.DecimalSerializer; import org.junit.Assert; import org.junit.Test; http://git-wip-us.apache.org/repos/asf/cassandra/blob/fc8b76f7/test/unit/org/apache/cassandra/db/marshal/BytesTypeTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/db/marshal/BytesTypeTest.java b/test/unit/org/apache/cassandra/db/marshal/BytesTypeTest.java index 24804fd..7897940 100644 --- a/test/unit/org/apache/cassandra/db/marshal/BytesTypeTest.java +++ b/test/unit/org/apache/cassandra/db/marshal/BytesTypeTest.java @@ -19,7 +19,7 @@ */ package org.apache.cassandra.db.marshal; -import org.apache.cassandra.type.MarshalException; +import org.apache.cassandra.serializers.MarshalException; import org.junit.Test; public class BytesTypeTest http://git-wip-us.apache.org/repos/asf/cassandra/blob/fc8b76f7/test/unit/org/apache/cassandra/db/marshal/CompositeTypeTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/db/marshal/CompositeTypeTest.java b/test/unit/org/apache/cassandra/db/marshal/CompositeTypeTest.java index fa31b9e..afb3913 100644 --- a/test/unit/org/apache/cassandra/db/marshal/CompositeTypeTest.java +++ b/test/unit/org/apache/cassandra/db/marshal/CompositeTypeTest.java @@ -19,14 +19,12 @@ package org.apache.cassandra.db.marshal; import java.nio.ByteBuffer; -import java.nio.charset.CharacterCodingException; import java.util.ArrayList; -import java.util.Arrays; import java.util.Iterator; import java.util.List; import java.util.UUID; -import org.apache.cassandra.type.MarshalException; +import org.apache.cassandra.serializers.MarshalException; import org.junit.Test; import static org.junit.Assert.fail; import static org.junit.Assert.assertEquals; @@ -37,7 +35,6 @@ import org.apache.cassandra.exceptions.ConfigurationException; import org.apache.cassandra.exceptions.SyntaxException; import org.apache.cassandra.db.*; import org.apache.cassandra.db.filter.QueryFilter; -import org.apache.cassandra.io.sstable.SSTableReader; import org.apache.cassandra.utils.*; public class CompositeTypeTest extends SchemaLoader http://git-wip-us.apache.org/repos/asf/cassandra/blob/fc8b76f7/test/unit/org/apache/cassandra/db/marshal/DynamicCompositeTypeTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/db/marshal/DynamicCompositeTypeTest.java b/test/unit/org/apache/cassandra/db/marshal/DynamicCompositeTypeTest.java index 8a4588d..e959b5f 100644 --- a/test/unit/org/apache/cassandra/db/marshal/DynamicCompositeTypeTest.java +++ b/test/unit/org/apache/cassandra/db/marshal/DynamicCompositeTypeTest.java @@ -24,7 +24,7 @@ import java.util.HashMap; import java.util.Map; import java.util.UUID; -import org.apache.cassandra.type.MarshalException; +import org.apache.cassandra.serializers.MarshalException; import org.junit.Test; import static org.junit.Assert.fail; http://git-wip-us.apache.org/repos/asf/cassandra/blob/fc8b76f7/test/unit/org/apache/cassandra/db/marshal/RoundTripTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/db/marshal/RoundTripTest.java b/test/unit/org/apache/cassandra/db/marshal/RoundTripTest.java index 4b0228a..89dbf01 100644 --- a/test/unit/org/apache/cassandra/db/marshal/RoundTripTest.java +++ b/test/unit/org/apache/cassandra/db/marshal/RoundTripTest.java @@ -23,7 +23,7 @@ package org.apache.cassandra.db.marshal; import com.google.common.base.Charsets; -import org.apache.cassandra.type.*; +import org.apache.cassandra.serializers.*; import org.apache.cassandra.utils.Hex; import org.apache.cassandra.utils.UUIDGen; import org.junit.Test; http://git-wip-us.apache.org/repos/asf/cassandra/blob/fc8b76f7/test/unit/org/apache/cassandra/db/marshal/TimeUUIDTypeTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/db/marshal/TimeUUIDTypeTest.java b/test/unit/org/apache/cassandra/db/marshal/TimeUUIDTypeTest.java index 2cd6da0..703845b 100644 --- a/test/unit/org/apache/cassandra/db/marshal/TimeUUIDTypeTest.java +++ b/test/unit/org/apache/cassandra/db/marshal/TimeUUIDTypeTest.java @@ -24,7 +24,7 @@ import java.util.Arrays; import java.util.Random; import java.util.UUID; -import org.apache.cassandra.type.MarshalException; +import org.apache.cassandra.serializers.MarshalException; import org.junit.Test; import static org.junit.Assert.assertEquals; http://git-wip-us.apache.org/repos/asf/cassandra/blob/fc8b76f7/test/unit/org/apache/cassandra/db/marshal/TypeValidationTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/db/marshal/TypeValidationTest.java b/test/unit/org/apache/cassandra/db/marshal/TypeValidationTest.java index 9f2b3e2..ed5e2bf 100644 --- a/test/unit/org/apache/cassandra/db/marshal/TypeValidationTest.java +++ b/test/unit/org/apache/cassandra/db/marshal/TypeValidationTest.java @@ -1,7 +1,7 @@ package org.apache.cassandra.db.marshal; import org.apache.cassandra.Util; -import org.apache.cassandra.type.MarshalException; +import org.apache.cassandra.serializers.MarshalException; import org.apache.cassandra.utils.UUIDGen; import org.junit.Test; http://git-wip-us.apache.org/repos/asf/cassandra/blob/fc8b76f7/test/unit/org/apache/cassandra/serializers/ClientUtilsTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/serializers/ClientUtilsTest.java b/test/unit/org/apache/cassandra/serializers/ClientUtilsTest.java new file mode 100644 index 0000000..877971e --- /dev/null +++ b/test/unit/org/apache/cassandra/serializers/ClientUtilsTest.java @@ -0,0 +1,71 @@ +package org.apache.cassandra.serializers; +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + * + */ + + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.net.UnknownHostException; +import java.nio.ByteBuffer; +import java.sql.Date; +import java.util.UUID; + +import org.apache.cassandra.utils.UUIDGen; +import org.junit.Test; + +public class ClientUtilsTest +{ + /** Exercises the classes in the clientutil jar to expose missing dependencies. */ + @Test + public void test() throws UnknownHostException + { + AsciiSerializer.instance.serialize(AsciiSerializer.instance.deserialize("string")); + BooleanSerializer.instance.serialize(BooleanSerializer.instance.deserialize(true)); + BytesSerializer.instance.serialize(BytesSerializer.instance.deserialize(ByteBuffer.wrap("string".getBytes()))); + + Date date = new Date(System.currentTimeMillis()); + ByteBuffer dateBB = TimestampSerializer.instance.deserialize(date); + TimestampSerializer.instance.serialize(dateBB); + assert (TimestampSerializer.instance.toString(date).equals(TimestampSerializer.instance.getString(dateBB))); + + DecimalSerializer.instance.serialize(DecimalSerializer.instance.deserialize(new BigDecimal(1))); + DoubleSerializer.instance.serialize(DoubleSerializer.instance.deserialize(new Double(1.0d))); + FloatSerializer.instance.serialize(FloatSerializer.instance.deserialize(new Float(1.0f))); + Int32Serializer.instance.serialize(Int32Serializer.instance.deserialize(1)); + IntegerSerializer.instance.serialize(IntegerSerializer.instance.deserialize(new BigInteger("1"))); + LongSerializer.instance.serialize(LongSerializer.instance.deserialize(1L)); + UTF8Serializer.instance.serialize(UTF8Serializer.instance.deserialize("string")); + + // UUIDGen + UUID uuid = UUIDGen.getTimeUUID(); + UUIDSerializer.instance.serialize(UUIDSerializer.instance.deserialize(uuid)); + + // Raise a MarshalException + try + { + UUIDSerializer.instance.getString(ByteBuffer.wrap("notauuid".getBytes())); + } + catch (MarshalException me) + { + // Success + } + } +} http://git-wip-us.apache.org/repos/asf/cassandra/blob/fc8b76f7/test/unit/org/apache/cassandra/type/ClientUtilsTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/type/ClientUtilsTest.java b/test/unit/org/apache/cassandra/type/ClientUtilsTest.java deleted file mode 100644 index 74d3e20..0000000 --- a/test/unit/org/apache/cassandra/type/ClientUtilsTest.java +++ /dev/null @@ -1,71 +0,0 @@ -package org.apache.cassandra.type; -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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. - * - */ - - -import java.math.BigDecimal; -import java.math.BigInteger; -import java.net.UnknownHostException; -import java.nio.ByteBuffer; -import java.sql.Date; -import java.util.UUID; - -import org.apache.cassandra.utils.UUIDGen; -import org.junit.Test; - -public class ClientUtilsTest -{ - /** Exercises the classes in the clientutil jar to expose missing dependencies. */ - @Test - public void test() throws UnknownHostException - { - AsciiSerializer.instance.serialize(AsciiSerializer.instance.deserialize("string")); - BooleanSerializer.instance.serialize(BooleanSerializer.instance.deserialize(true)); - BytesSerializer.instance.serialize(BytesSerializer.instance.deserialize(ByteBuffer.wrap("string".getBytes()))); - - Date date = new Date(System.currentTimeMillis()); - ByteBuffer dateBB = DateSerializer.instance.deserialize(date); - DateSerializer.instance.serialize(dateBB); - assert (DateSerializer.instance.toString(date).equals(DateSerializer.instance.getString(dateBB))); - - DecimalSerializer.instance.serialize(DecimalSerializer.instance.deserialize(new BigDecimal(1))); - DoubleSerializer.instance.serialize(DoubleSerializer.instance.deserialize(new Double(1.0d))); - FloatSerializer.instance.serialize(FloatSerializer.instance.deserialize(new Float(1.0f))); - Int32Serializer.instance.serialize(Int32Serializer.instance.deserialize(1)); - IntegerSerializer.instance.serialize(IntegerSerializer.instance.deserialize(new BigInteger("1"))); - LongSerializer.instance.serialize(LongSerializer.instance.deserialize(1L)); - UTF8Serializer.instance.serialize(UTF8Serializer.instance.deserialize("string")); - - // UUIDGen - UUID uuid = UUIDGen.getTimeUUID(); - UUIDSerializer.instance.serialize(UUIDSerializer.instance.deserialize(uuid)); - - // Raise a MarshalException - try - { - UUIDSerializer.instance.getString(ByteBuffer.wrap("notauuid".getBytes())); - } - catch (MarshalException me) - { - // Success - } - } -}