Repository: gora Updated Branches: refs/heads/master a8398651d -> 446f42ea3
http://git-wip-us.apache.org/repos/asf/gora/blob/4346216f/gora-ignite/src/test/java/org/apache/gora/ignite/GoraIgniteTestDriver.java ---------------------------------------------------------------------- diff --git a/gora-ignite/src/test/java/org/apache/gora/ignite/GoraIgniteTestDriver.java b/gora-ignite/src/test/java/org/apache/gora/ignite/GoraIgniteTestDriver.java new file mode 100644 index 0000000..1e03717 --- /dev/null +++ b/gora-ignite/src/test/java/org/apache/gora/ignite/GoraIgniteTestDriver.java @@ -0,0 +1,73 @@ +/** + * 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.gora.ignite; + +import org.apache.ignite.minicluster.MiniIgniteCluster; +import org.apache.ignite.minicluster.MiniIgniteConfig; +import org.apache.gora.GoraTestDriver; +import org.apache.gora.ignite.store.IgniteStore; +import org.junit.Rule; +import org.junit.rules.TemporaryFolder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; + +/** + * @author lmcgibbn + * + */ +public class GoraIgniteTestDriver extends GoraTestDriver { + + private static final Logger LOG = LoggerFactory.getLogger(GoraIgniteTestDriver.class); + private static MiniIgniteCluster cluster = null; + private static final String PASSWORD = "drowssap"; + + @Rule + public TemporaryFolder tmpDir = new TemporaryFolder(); + + public GoraIgniteTestDriver() throws Exception { + super(IgniteStore.class); + } + + @Override + public void setUpClass() throws IOException, InterruptedException { + log.info("Starting Ignite MiniIgniteCluster..."); + try { + tmpDir.create(); + MiniIgniteConfig miniCfg = new MiniIgniteConfig(tmpDir.getRoot(), PASSWORD); + miniCfg.setInstanceName("goraTest"); + miniCfg.setZooKeeperPort(56321); + cluster = new MiniIgniteCluster(miniCfg); + cluster.start(); + } catch (Exception e) { + LOG.error("Error starting Ignite MiniIgniteCluster: {}", e.getMessage()); + // cleanup + tearDownClass(); + } + } + + @Override + public void tearDownClass() throws IOException, InterruptedException { + log.info("Shutting down Ignite MiniIgniteCluster..."); + if (cluster != null) { + cluster.stop(); + } + tmpDir.delete(); + } +} http://git-wip-us.apache.org/repos/asf/gora/blob/4346216f/gora-ignite/src/test/java/org/apache/gora/ignite/package-info.java ---------------------------------------------------------------------- diff --git a/gora-ignite/src/test/java/org/apache/gora/ignite/package-info.java b/gora-ignite/src/test/java/org/apache/gora/ignite/package-info.java new file mode 100644 index 0000000..f536961 --- /dev/null +++ b/gora-ignite/src/test/java/org/apache/gora/ignite/package-info.java @@ -0,0 +1,21 @@ +/** + * 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. + */ +/** + * Tests for <code>gora-ignite</code> including + * the test driver for {@link org.apache.gora.ignite.store.IgniteStoreTest} + */ +package org.apache.gora.ignite; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/gora/blob/4346216f/gora-ignite/src/test/java/org/apache/gora/ignite/store/AuthenticationTokenTest.java ---------------------------------------------------------------------- diff --git a/gora-ignite/src/test/java/org/apache/gora/ignite/store/AuthenticationTokenTest.java b/gora-ignite/src/test/java/org/apache/gora/ignite/store/AuthenticationTokenTest.java new file mode 100644 index 0000000..bb77bee --- /dev/null +++ b/gora-ignite/src/test/java/org/apache/gora/ignite/store/AuthenticationTokenTest.java @@ -0,0 +1,90 @@ +/** + * 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.gora.ignite.store; + +import java.util.List; +import java.util.Properties; +import org.apache.ignite.minicluster.MiniIgniteCluster; +import org.apache.gora.examples.generated.Employee; +import org.apache.gora.query.PartitionQuery; +import org.apache.gora.store.DataStore; +import org.apache.gora.store.DataStoreFactory; +import org.apache.hadoop.conf.Configuration; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Tests authentication token is serialized correctly. + */ +public class AuthenticationTokenTest { + private static final Logger LOG = LoggerFactory.getLogger(AuthenticationTokenTest.class); + + private static final String GORA_DATASTORE = + DataStoreFactory.GORA + "." + DataStoreFactory.DATASTORE + "."; + private static final String PASSWORD = "password"; + + @Rule + public TemporaryFolder temporaryFolder = new TemporaryFolder(); + + private MiniIgniteCluster cluster; + private DataStore<String, Employee> employeeStore; + + @Before + @SuppressWarnings("unchecked") + public void setUp() throws Exception { + cluster = new MiniIgniteCluster(temporaryFolder.getRoot(), PASSWORD); + cluster.start(); + + Properties properties = DataStoreFactory.createProps(); + properties.setProperty( + GORA_DATASTORE + IgniteStore.MOCK_PROPERTY, + "false"); + properties.setProperty( + GORA_DATASTORE + IgniteStore.INSTANCE_NAME_PROPERTY, + cluster.getInstanceName()); + properties.setProperty( + GORA_DATASTORE + IgniteStore.ZOOKEEPERS_NAME_PROPERTY, + cluster.getZooKeepers()); + properties.setProperty( + GORA_DATASTORE + IgniteStore.PASSWORD_PROPERTY, + PASSWORD); + + employeeStore = DataStoreFactory.createDataStore( + IgniteStore.class, + String.class, + Employee.class, + new Configuration(), + properties); + } + + @After + public void tearDown() throws Exception { + cluster.stop(); + } + + @Test + public void testAuthenticationTokenIsSerializedCorrectly() throws Exception { + List<PartitionQuery<String, Employee>> partitions = + employeeStore.getPartitions(employeeStore.newQuery()); + LOG.debug("partitions {}", partitions); + } +} http://git-wip-us.apache.org/repos/asf/gora/blob/4346216f/gora-ignite/src/test/java/org/apache/gora/ignite/store/IgniteStoreTest.java ---------------------------------------------------------------------- diff --git a/gora-ignite/src/test/java/org/apache/gora/ignite/store/IgniteStoreTest.java b/gora-ignite/src/test/java/org/apache/gora/ignite/store/IgniteStoreTest.java new file mode 100644 index 0000000..b42d344 --- /dev/null +++ b/gora-ignite/src/test/java/org/apache/gora/ignite/store/IgniteStoreTest.java @@ -0,0 +1,87 @@ +/** + * 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.gora.ignite.store; + +import java.io.IOException; + +import org.apache.gora.ignite.GoraIgniteTestDriver; +import org.apache.gora.examples.generated.Employee; +import org.apache.gora.examples.generated.WebPage; +import org.apache.gora.store.DataStore; +import org.apache.gora.store.DataStoreFactory; +import org.apache.gora.store.DataStoreTestBase; +import static org.apache.gora.store.DataStoreTestBase.log; +import org.apache.gora.store.DataStoreTestUtil; +import static org.apache.gora.store.DataStoreTestUtil.testResultSize; +import org.apache.hadoop.conf.Configuration; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +/** + * Tests extending {@link org.apache.gora.store.DataStoreTestBase} + * which run the base JUnit test suite for Gora. + */ +public class IgniteStoreTest extends DataStoreTestBase { + + static { + try { + setTestDriver(new GoraIgniteTestDriver()); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + @Before + public void setUp() throws Exception { + super.setUp(); + } + + public GoraIgniteTestDriver getTestDriver() { + return (GoraIgniteTestDriver) testDriver; + } + + //Until GORA-66 is resolved this test will always fail, so + //do not run it + @Ignore("skipped until GORA-66 is resolved") + @Override + public void testDeleteByQueryFields() throws IOException { + } + + @Test + @Ignore("Ignite does not support Result#size() without limit set") + @Override + public void testResultSize() throws Exception { + } + + @Test + @Ignore("Ignite does not support Result#size() without limit set") + @Override + public void testResultSizeStartKey() throws Exception { + } + + @Ignore("Ignite does not support Result#size() without limit set") + @Override + public void testResultSizeEndKey() throws Exception { + } + + @Test + @Ignore("Ignite does not support Result#size() without limit set") + @Override + public void testResultSizeKeyRange() throws Exception { + } +} http://git-wip-us.apache.org/repos/asf/gora/blob/4346216f/gora-ignite/src/test/java/org/apache/gora/ignite/store/PartitionTest.java ---------------------------------------------------------------------- diff --git a/gora-ignite/src/test/java/org/apache/gora/ignite/store/PartitionTest.java b/gora-ignite/src/test/java/org/apache/gora/ignite/store/PartitionTest.java new file mode 100644 index 0000000..1c77656 --- /dev/null +++ b/gora-ignite/src/test/java/org/apache/gora/ignite/store/PartitionTest.java @@ -0,0 +1,96 @@ +/** + * 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.gora.ignite.store; + +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; +import java.io.IOException; + +import org.apache.gora.ignite.encoders.Encoder; +import org.apache.gora.ignite.encoders.SignedBinaryEncoder; +import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +/** + * + */ +public class PartitionTest { + // TODO test more types + + private static Encoder encoder = new SignedBinaryEncoder(); + + static long encl(long l) throws IOException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(baos); + try { + dos.writeLong(l); + dos.flush(); + } catch (IOException e) { + throw new RuntimeException(e); + } + return encoder.decodeLong(baos.toByteArray()); + } + + @Test + public void test1() throws IOException { + assertEquals(encl(0x006f000000000000l), (long) IgniteStore.followingKey(encoder, Long.class, new byte[] {0x00, 0x6f})); + assertEquals(encl(1l), (long) IgniteStore.followingKey(encoder, Long.class, new byte[] {0, 0, 0, 0, 0, 0, 0, 0})); + assertEquals(encl(0x106f000000000001l), (long) IgniteStore.followingKey(encoder, Long.class, new byte[] {0x10, 0x6f, 0, 0, 0, 0, 0, 0})); + assertEquals( + encl(-1l), + (long) IgniteStore.followingKey(encoder, Long.class, new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, + (byte) 0xff, + (byte) 0xfe})); + + assertEquals(encl(0x8000000000000001l), (long) IgniteStore.followingKey(encoder, Long.class, new byte[] {(byte) 0x80, 0, 0, 0, 0, 0, 0, 0})); + assertEquals( + encl(0x8000000000000000l), + (long) IgniteStore.followingKey(encoder, Long.class, new byte[] {(byte) 0x7f, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, + (byte) 0xff, + (byte) 0xff})); + + + try { + IgniteStore.followingKey(encoder, Long.class, + new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff}); + assertTrue(false); + } catch (IllegalArgumentException iea) { + + } + } + + @Test + public void test2() throws IOException { + assertEquals(encl(0x00ffffffffffffffl), (long) IgniteStore.lastPossibleKey(encoder, Long.class, new byte[] {0x01})); + assertEquals(encl(0x006effffffffffffl), (long) IgniteStore.lastPossibleKey(encoder, Long.class, new byte[] {0x00, 0x6f})); + assertEquals(encl(0xff6effffffffffffl), (long) IgniteStore.lastPossibleKey(encoder, Long.class, new byte[] {(byte) 0xff, 0x6f})); + assertEquals(encl(0xfffeffffffffffffl), (long) IgniteStore.lastPossibleKey(encoder, Long.class, new byte[] {(byte) 0xff, (byte) 0xff})); + assertEquals(encl(0l), (long) IgniteStore.lastPossibleKey(encoder, Long.class, new byte[] {(byte) 0, 0, 0, 0, 0, 0, 0, 0})); + + assertEquals(encl(0x7effffffffffffffl), (long) IgniteStore.lastPossibleKey(encoder, Long.class, new byte[] {(byte) 0x7f})); + assertEquals(encl(0x7fffffffffffffffl), (long) IgniteStore.lastPossibleKey(encoder, Long.class, new byte[] {(byte) 0x80})); + assertEquals(encl(0x80ffffffffffffffl), (long) IgniteStore.lastPossibleKey(encoder, Long.class, new byte[] {(byte) 0x81})); + + try { + IgniteStore.lastPossibleKey(encoder, Long.class, new byte[] {(byte) 0, 0, 0, 0, 0, 0, 0}); + assertTrue(false); + } catch (IllegalArgumentException iea) { + + } + } +} http://git-wip-us.apache.org/repos/asf/gora/blob/4346216f/gora-ignite/src/test/java/org/apache/gora/ignite/store/package-info.java ---------------------------------------------------------------------- diff --git a/gora-ignite/src/test/java/org/apache/gora/ignite/store/package-info.java b/gora-ignite/src/test/java/org/apache/gora/ignite/store/package-info.java new file mode 100644 index 0000000..a41e085 --- /dev/null +++ b/gora-ignite/src/test/java/org/apache/gora/ignite/store/package-info.java @@ -0,0 +1,21 @@ +/* + * 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. + */ +/** + * This package contains all the unit tests for basic CRUD operations + * functionality of the Ignite dataStore. + */ +package org.apache.gora.ignite.store; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/gora/blob/4346216f/gora-ignite/src/test/java/org/apache/gora/ignite/util/HexEncoderTest.java ---------------------------------------------------------------------- diff --git a/gora-ignite/src/test/java/org/apache/gora/ignite/util/HexEncoderTest.java b/gora-ignite/src/test/java/org/apache/gora/ignite/util/HexEncoderTest.java new file mode 100644 index 0000000..0d4e5e6 --- /dev/null +++ b/gora-ignite/src/test/java/org/apache/gora/ignite/util/HexEncoderTest.java @@ -0,0 +1,56 @@ +/** + * 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.gora.ignite.util; + +import java.nio.charset.Charset; +import org.apache.gora.ignite.encoders.HexEncoder; +import static org.junit.Assert.assertEquals; +import org.junit.Test; + +/** + * + */ +public class HexEncoderTest { + + @Test + public void testByte() { + HexEncoder encoder = new HexEncoder(); + + assertEquals("12", new String(encoder.encodeByte((byte) 0x12), Charset.defaultCharset())); + assertEquals("f2", new String(encoder.encodeByte((byte) 0xf2), Charset.defaultCharset())); + + byte b = Byte.MIN_VALUE; + while (b != Byte.MAX_VALUE) { + assertEquals(b, encoder.decodeByte(encoder.encodeByte(b))); + b++; + } + } + + @Test + public void testShort() { + HexEncoder encoder = new HexEncoder(); + + assertEquals("1234", new String(encoder.encodeShort((short) 0x1234), Charset.defaultCharset())); + assertEquals("f234", new String(encoder.encodeShort((short) 0xf234), Charset.defaultCharset())); + + short s = Short.MIN_VALUE; + while (s != Short.MAX_VALUE) { + assertEquals(s, encoder.decodeShort(encoder.encodeShort(s))); + s++; + } + } +} http://git-wip-us.apache.org/repos/asf/gora/blob/4346216f/gora-ignite/src/test/java/org/apache/gora/ignite/util/SignedBinaryEncoderTest.java ---------------------------------------------------------------------- diff --git a/gora-ignite/src/test/java/org/apache/gora/ignite/util/SignedBinaryEncoderTest.java b/gora-ignite/src/test/java/org/apache/gora/ignite/util/SignedBinaryEncoderTest.java new file mode 100644 index 0000000..c943e73 --- /dev/null +++ b/gora-ignite/src/test/java/org/apache/gora/ignite/util/SignedBinaryEncoderTest.java @@ -0,0 +1,167 @@ +/** + * 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.gora.ignite.util; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; + +import org.apache.gora.ignite.encoders.SignedBinaryEncoder; +import org.apache.hadoop.io.Text; +import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +/** + * + */ +public class SignedBinaryEncoderTest { + @Test + public void testShort() throws IOException { + short s = Short.MIN_VALUE; + Text prev = null; + + SignedBinaryEncoder encoder = new SignedBinaryEncoder(); + + while (true) { + byte[] enc = encoder.encodeShort(s); + assertEquals(s, encoder.decodeShort(enc)); + Text current = new Text(enc); + if (prev != null) + assertTrue(prev.compareTo(current) < 0); + prev = current; + s++; + if (s == Short.MAX_VALUE) + break; + } + } + + private void testInt(int start, int finish) throws IOException { + int i = start; + Text prev = null; + + SignedBinaryEncoder encoder = new SignedBinaryEncoder(); + + while (true) { + byte[] enc = encoder.encodeInt(i); + assertEquals(i, encoder.decodeInt(enc)); + Text current = new Text(enc); + if (prev != null) + assertTrue(prev.compareTo(current) < 0); + prev = current; + i++; + if (i == finish) + break; + } + } + + @Test + public void testInt() throws IOException { + testInt(Integer.MIN_VALUE, Integer.MIN_VALUE + (1 << 16)); + testInt(-(1 << 15), (1 << 15)); + testInt(Integer.MAX_VALUE - (1 << 16), Integer.MAX_VALUE); + } + + private void testLong(long start, long finish) throws IOException { + long l = start; + Text prev = null; + + SignedBinaryEncoder encoder = new SignedBinaryEncoder(); + + while (true) { + byte[] enc = encoder.encodeLong(l); + assertEquals(l, encoder.decodeLong(enc)); + Text current = new Text(enc); + if (prev != null) + assertTrue(prev.compareTo(current) < 0); + prev = current; + l++; + if (l == finish) + break; + } + } + + @Test + public void testLong() throws IOException { + testLong(Long.MIN_VALUE, Long.MIN_VALUE + (1 << 16)); + testLong(-(1 << 15), (1 << 15)); + testLong(Long.MAX_VALUE - (1 << 16), Long.MAX_VALUE); + } + + @Test + public void testDouble() throws IOException { + + ArrayList<Double> testData = new ArrayList<>(); + testData.add(Double.NEGATIVE_INFINITY); + testData.add(Double.MIN_VALUE); + testData.add(Math.nextUp(Double.NEGATIVE_INFINITY)); + testData.add(Math.pow(10.0, 30.0) * -1.0); + testData.add(Math.pow(10.0, 30.0)); + testData.add(Math.pow(10.0, -30.0) * -1.0); + testData.add(Math.pow(10.0, -30.0)); + testData.add(Math.nextAfter(0.0, Double.NEGATIVE_INFINITY)); + testData.add(0.0); + testData.add(Math.nextAfter(Double.MAX_VALUE, Double.NEGATIVE_INFINITY)); + testData.add(Double.MAX_VALUE); + testData.add(Double.POSITIVE_INFINITY); + + Collections.sort(testData); + + SignedBinaryEncoder encoder = new SignedBinaryEncoder(); + + for (int i = 0; i < testData.size(); i++) { + byte[] enc = encoder.encodeDouble(testData.get(i)); + assertEquals(testData.get(i), (Double) encoder.decodeDouble(enc)); + if (i > 1) { + assertTrue("Checking " + testData.get(i) + " > " + testData.get(i - 1), + new Text(enc).compareTo(new Text(encoder.encodeDouble(testData.get(i - 1)))) > 0); + } + } + } + + @Test + public void testFloat() throws IOException { + + ArrayList<Float> testData = new ArrayList<>(); + testData.add(Float.NEGATIVE_INFINITY); + testData.add(Float.MIN_VALUE); + testData.add(Math.nextUp(Float.NEGATIVE_INFINITY)); + testData.add((float) Math.pow(10.0f, 30.0f) * -1.0f); + testData.add((float) Math.pow(10.0f, 30.0f)); + testData.add((float) Math.pow(10.0f, -30.0f) * -1.0f); + testData.add((float) Math.pow(10.0f, -30.0f)); + testData.add(Math.nextAfter(0.0f, Float.NEGATIVE_INFINITY)); + testData.add(0.0f); + testData.add(Math.nextAfter(Float.MAX_VALUE, Float.NEGATIVE_INFINITY)); + testData.add(Float.MAX_VALUE); + testData.add(Float.POSITIVE_INFINITY); + + Collections.sort(testData); + + SignedBinaryEncoder encoder = new SignedBinaryEncoder(); + + for (int i = 0; i < testData.size(); i++) { + byte[] enc = encoder.encodeFloat(testData.get(i)); + assertEquals(testData.get(i), (Float)encoder.decodeFloat(enc)); + if (i > 1) { + assertTrue("Checking " + testData.get(i) + " > " + testData.get(i - 1), + new Text(enc).compareTo(new Text(encoder.encodeFloat(testData.get(i - 1)))) > 0); + } + } + } + +} http://git-wip-us.apache.org/repos/asf/gora/blob/4346216f/gora-ignite/src/test/java/org/apache/gora/ignite/util/package-info.java ---------------------------------------------------------------------- diff --git a/gora-ignite/src/test/java/org/apache/gora/ignite/util/package-info.java b/gora-ignite/src/test/java/org/apache/gora/ignite/util/package-info.java new file mode 100644 index 0000000..afcd619 --- /dev/null +++ b/gora-ignite/src/test/java/org/apache/gora/ignite/util/package-info.java @@ -0,0 +1,20 @@ +/* + * 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. + */ +/** + * This package contains all the unit tests for utils of the Ignite dataStore. + */ +package org.apache.gora.ignite.util; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/gora/blob/4346216f/gora-ignite/src/test/resources/gora-accumulo-mapping.xml ---------------------------------------------------------------------- diff --git a/gora-ignite/src/test/resources/gora-accumulo-mapping.xml b/gora-ignite/src/test/resources/gora-accumulo-mapping.xml new file mode 100644 index 0000000..4d036c6 --- /dev/null +++ b/gora-ignite/src/test/resources/gora-accumulo-mapping.xml @@ -0,0 +1,59 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- + 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. +--> + +<gora-otd> + <table name="AccessLog"> + <config key="table.file.compress.blocksize" value="32K"/> + </table> + + <class name="org.apache.gora.tutorial.log.generated.Pageview" keyClass="java.lang.Long" table="AccessLog"> + <field name="url" family="common" qualifier="url"/> + <field name="timestamp" family="common" qualifier="timestamp"/> + <field name="ip" family="common" qualifier="ip" /> + <field name="httpMethod" family="http" qualifier="httpMethod"/> + <field name="httpStatusCode" family="http" qualifier="httpStatusCode"/> + <field name="responseSize" family="http" qualifier="responseSize"/> + <field name="referrer" family="misc" qualifier="referrer"/> + <field name="userAgent" family="misc" qualifier="userAgent"/> + </class> + + <class name="org.apache.gora.examples.generated.Employee" keyClass="java.lang.String" table="Employee"> + <field name="name" family="info" qualifier="nm"/> + <field name="dateOfBirth" family="info" qualifier="db"/> + <field name="ssn" family="info" qualifier="sn"/> + <field name="salary" family="info" qualifier="sl"/> + <field name="boss" family="info" qualifier="bs"/> + <field name="webpage" family="info" qualifier="wp"/> + </class> + + <class name="org.apache.gora.examples.generated.WebPage" keyClass="java.lang.String" table="WebPage"> + <field name="url" family="common" qualifier="u"/> + <field name="content" family="content" qualifier="c"/> + <field name="parsedContent" family="parsedContent"/> + <field name="outlinks" family="outlinks"/> + <field name="headers" family="headers"/> + <field name="metadata" family="common" qualifier="metadata"/> + <field name="byteData" family="byteData" qualifier="byteData"/> + <field name="stringData" family="stringData" qualifier="stringData"/> + </class> + + <class name="org.apache.gora.examples.generated.TokenDatum" keyClass="java.lang.String"> + <field name="count" family="common" qualifier="count"/> + </class> +</gora-otd> http://git-wip-us.apache.org/repos/asf/gora/blob/4346216f/gora-ignite/src/test/resources/gora.properties ---------------------------------------------------------------------- diff --git a/gora-ignite/src/test/resources/gora.properties b/gora-ignite/src/test/resources/gora.properties new file mode 100644 index 0000000..5cf0e25 --- /dev/null +++ b/gora-ignite/src/test/resources/gora.properties @@ -0,0 +1,21 @@ +# 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. + +gora.datastore.default=org.apache.gora.ignite.store.IgniteStore +gora.datastore.ignite.mock=false +gora.datastore.ignite.instance=goraTest +gora.datastore.ignite.zookeepers=localhost:56321 +gora.datastore.ignite.user=root +gora.datastore.ignite.password=drowssap \ No newline at end of file http://git-wip-us.apache.org/repos/asf/gora/blob/4346216f/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index 48ff3b4..88b9b52 100644 --- a/pom.xml +++ b/pom.xml @@ -760,6 +760,7 @@ <module>gora-tutorial</module> <module>sources-dist</module> <module>gora-aerospike</module> + <module>gora-ignite</module> </modules> <properties>