From 08872b83035d79ffb1e4cb29ab823732f2d599f5 Mon Sep 17 00:00:00 2001 From: 51-code <146736881+51-code@users.noreply.github.com> Date: Mon, 9 Dec 2024 12:37:38 +0200 Subject: [PATCH] BloomFilter equals tests and refactoring (#448) * Add equals tests to BloomFilter classes, rename ModeFromBloomContext, refactor ToBloomFilter * Fix equals tests in BloomFilter classes * Rename ToBloomFilter to BloomFilterBlob --- pom.xml | 6 + .../TeragrepTransformation.java | 4 +- ...loomContext.java => ContextBloomMode.java} | 4 +- .../teragrep/bloomfilter/BloomFilterBlob.java | 94 +++++++++ .../BloomFilterForeachPartitionFunction.java | 15 ++ .../bloomfilter/TeragrepBloomFilter.java | 2 +- .../teragrep/bloomfilter/ToBloomFilter.java | 188 ------------------ ...lterTest.java => BloomFilterBlobTest.java} | 32 +-- ...oomFilterForeachPartitionFunctionTest.java | 60 ++++++ .../bloomfilter/BloomFilterTableTest.java | 6 + .../teragrep/bloomfilter/FilterTypesTest.java | 6 + .../JournalDBNameFromConfigTest.java | 57 ++++++ .../bloomfilter/LazyConnectionTest.java | 57 ++++++ .../teragrep/bloomfilter/TableSQLTest.java | 9 + .../bloomfilter/TeragrepBloomFilterTest.java | 9 + 15 files changed, 343 insertions(+), 206 deletions(-) rename src/main/java/com/teragrep/pth10/ast/commands/transformstatement/teragrep/{ModeFromBloomContext.java => ContextBloomMode.java} (94%) create mode 100644 src/main/java/com/teragrep/pth10/steps/teragrep/bloomfilter/BloomFilterBlob.java delete mode 100644 src/main/java/com/teragrep/pth10/steps/teragrep/bloomfilter/ToBloomFilter.java rename src/test/java/com/teragrep/pth10/steps/teragrep/bloomfilter/{ToBloomFilterTest.java => BloomFilterBlobTest.java} (82%) create mode 100644 src/test/java/com/teragrep/pth10/steps/teragrep/bloomfilter/BloomFilterForeachPartitionFunctionTest.java create mode 100644 src/test/java/com/teragrep/pth10/steps/teragrep/bloomfilter/JournalDBNameFromConfigTest.java create mode 100644 src/test/java/com/teragrep/pth10/steps/teragrep/bloomfilter/LazyConnectionTest.java diff --git a/pom.xml b/pom.xml index 7f6113f3..48693c42 100644 --- a/pom.xml +++ b/pom.xml @@ -120,6 +120,12 @@ 2.0.0 test + + nl.jqno.equalsverifier + equalsverifier + 3.17.4 + test + com.teragrep pth_06 diff --git a/src/main/java/com/teragrep/pth10/ast/commands/transformstatement/TeragrepTransformation.java b/src/main/java/com/teragrep/pth10/ast/commands/transformstatement/TeragrepTransformation.java index aef6d3d9..f0e93924 100644 --- a/src/main/java/com/teragrep/pth10/ast/commands/transformstatement/TeragrepTransformation.java +++ b/src/main/java/com/teragrep/pth10/ast/commands/transformstatement/TeragrepTransformation.java @@ -53,7 +53,7 @@ import com.teragrep.pth10.ast.bo.Token; import com.teragrep.pth10.ast.commands.logicalstatement.LogicalStatementCatalyst; import com.teragrep.pth10.ast.commands.logicalstatement.LogicalStatementXML; -import com.teragrep.pth10.ast.commands.transformstatement.teragrep.ModeFromBloomContext; +import com.teragrep.pth10.ast.commands.transformstatement.teragrep.ContextBloomMode; import com.teragrep.pth10.ast.commands.transformstatement.teragrep.EstimateColumnFromBloomContext; import com.teragrep.pth10.ast.commands.transformstatement.teragrep.InputColumnFromBloomContext; import com.teragrep.pth10.ast.commands.transformstatement.teragrep.OutputColumnFromBloomContext; @@ -480,7 +480,7 @@ public Node visitT_bloomModeParameter(final DPLParser.T_bloomModeParameterContex @Override public Node visitT_bloomOptionParameter(final DPLParser.T_bloomOptionParameterContext ctx) { // values from context - final ContextValue mode = new ModeFromBloomContext(ctx); + final ContextValue mode = new ContextBloomMode(ctx); final ContextValue inputCol = new InputColumnFromBloomContext(ctx); final ContextValue outputCol = new OutputColumnFromBloomContext(ctx, inputCol.value()); final ContextValue estimateCol = new EstimateColumnFromBloomContext(ctx, inputCol.value()); diff --git a/src/main/java/com/teragrep/pth10/ast/commands/transformstatement/teragrep/ModeFromBloomContext.java b/src/main/java/com/teragrep/pth10/ast/commands/transformstatement/teragrep/ContextBloomMode.java similarity index 94% rename from src/main/java/com/teragrep/pth10/ast/commands/transformstatement/teragrep/ModeFromBloomContext.java rename to src/main/java/com/teragrep/pth10/ast/commands/transformstatement/teragrep/ContextBloomMode.java index 104839ac..41110b84 100644 --- a/src/main/java/com/teragrep/pth10/ast/commands/transformstatement/teragrep/ModeFromBloomContext.java +++ b/src/main/java/com/teragrep/pth10/ast/commands/transformstatement/teragrep/ContextBloomMode.java @@ -49,11 +49,11 @@ import com.teragrep.pth10.steps.teragrep.TeragrepBloomStep; import com.teragrep.pth_03.antlr.DPLParser; -public final class ModeFromBloomContext implements ContextValue { +public final class ContextBloomMode implements ContextValue { private final DPLParser.T_bloomOptionParameterContext ctx; - public ModeFromBloomContext(final DPLParser.T_bloomOptionParameterContext ctx) { + public ContextBloomMode(final DPLParser.T_bloomOptionParameterContext ctx) { this.ctx = ctx; } diff --git a/src/main/java/com/teragrep/pth10/steps/teragrep/bloomfilter/BloomFilterBlob.java b/src/main/java/com/teragrep/pth10/steps/teragrep/bloomfilter/BloomFilterBlob.java new file mode 100644 index 00000000..578d37f9 --- /dev/null +++ b/src/main/java/com/teragrep/pth10/steps/teragrep/bloomfilter/BloomFilterBlob.java @@ -0,0 +1,94 @@ +/* + * Teragrep Data Processing Language (DPL) translator for Apache Spark (pth_10) + * Copyright (C) 2019-2024 Suomen Kanuuna Oy + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + * + * Additional permission under GNU Affero General Public License version 3 + * section 7 + * + * If you modify this Program, or any covered work, by linking or combining it + * with other code, such other code is not for that reason alone subject to any + * of the requirements of the GNU Affero GPL version 3 as long as this Program + * is the same Program as licensed from Suomen Kanuuna Oy without any additional + * modifications. + * + * Supplemented terms under GNU Affero General Public License version 3 + * section 7 + * + * Origin of the software must be attributed to Suomen Kanuuna Oy. Any modified + * versions must be marked as "Modified version of" The Program. + * + * Names of the licensors and authors may not be used for publicity purposes. + * + * No rights are granted for use of trade names, trademarks, or service marks + * which are in The Program if any. + * + * Licensee must indemnify licensors and authors for any liability that these + * contractual assumptions impose on licensors and authors. + * + * To the extent this program is licensed as part of the Commercial versions of + * Teragrep, the applicable Commercial License may apply to this file if you as + * a licensee so wish it. + */ +package com.teragrep.pth10.steps.teragrep.bloomfilter; + +import org.apache.spark.util.sketch.BloomFilter; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.util.Arrays; + +/** + * BloomFilter from byte[] used in a constructor of TeragrepBloomFilter + * + * @see TeragrepBloomFilter + */ +public final class BloomFilterBlob { + + private final byte[] bytes; + + public BloomFilterBlob(final byte[] bytes) { + this.bytes = bytes; + } + + public BloomFilter toBloomFilter() { + final BloomFilter filter; + try (ByteArrayInputStream bais = new ByteArrayInputStream(bytes)) { + filter = BloomFilter.readFrom(bais); + } + catch (IOException e) { + throw new RuntimeException("Error reading bytes to filter: " + e.getMessage()); + } + return filter; + } + + @Override + public boolean equals(final Object object) { + if (this == object) + return true; + if (object == null) + return false; + if (object.getClass() != this.getClass()) + return false; + final BloomFilterBlob cast = (BloomFilterBlob) object; + return Arrays.equals(this.bytes, cast.bytes); + } + + @Override + public int hashCode() { + return Arrays.hashCode(bytes); + } +} diff --git a/src/main/java/com/teragrep/pth10/steps/teragrep/bloomfilter/BloomFilterForeachPartitionFunction.java b/src/main/java/com/teragrep/pth10/steps/teragrep/bloomfilter/BloomFilterForeachPartitionFunction.java index 8013f931..03262b01 100644 --- a/src/main/java/com/teragrep/pth10/steps/teragrep/bloomfilter/BloomFilterForeachPartitionFunction.java +++ b/src/main/java/com/teragrep/pth10/steps/teragrep/bloomfilter/BloomFilterForeachPartitionFunction.java @@ -51,6 +51,7 @@ import java.sql.Connection; import java.util.Iterator; +import java.util.Objects; public final class BloomFilterForeachPartitionFunction implements ForeachPartitionFunction { @@ -101,4 +102,18 @@ public void call(final Iterator iter) throws Exception { conn.commit(); } } + + @Override + public boolean equals(final Object o) { + if (o == null || getClass() != o.getClass()) + return false; + final BloomFilterForeachPartitionFunction cast = (BloomFilterForeachPartitionFunction) o; + return filterTypes.equals(cast.filterTypes) && lazyConnection.equals(cast.lazyConnection) + && overwrite == cast.overwrite && tableName.equals(cast.tableName) && regex.equals(cast.regex); + } + + @Override + public int hashCode() { + return Objects.hash(filterTypes, lazyConnection, overwrite, tableName, regex); + } } diff --git a/src/main/java/com/teragrep/pth10/steps/teragrep/bloomfilter/TeragrepBloomFilter.java b/src/main/java/com/teragrep/pth10/steps/teragrep/bloomfilter/TeragrepBloomFilter.java index 53fe59ff..65dc7306 100644 --- a/src/main/java/com/teragrep/pth10/steps/teragrep/bloomfilter/TeragrepBloomFilter.java +++ b/src/main/java/com/teragrep/pth10/steps/teragrep/bloomfilter/TeragrepBloomFilter.java @@ -79,7 +79,7 @@ public TeragrepBloomFilter( String tableName, String regex ) { - this(partition, new ToBloomFilter(bytes), connection, filterTypes, tableName, regex); + this(partition, new BloomFilterBlob(bytes).toBloomFilter(), connection, filterTypes, tableName, regex); } public TeragrepBloomFilter( diff --git a/src/main/java/com/teragrep/pth10/steps/teragrep/bloomfilter/ToBloomFilter.java b/src/main/java/com/teragrep/pth10/steps/teragrep/bloomfilter/ToBloomFilter.java deleted file mode 100644 index 1e4b5208..00000000 --- a/src/main/java/com/teragrep/pth10/steps/teragrep/bloomfilter/ToBloomFilter.java +++ /dev/null @@ -1,188 +0,0 @@ -/* - * Teragrep Data Processing Language (DPL) translator for Apache Spark (pth_10) - * Copyright (C) 2019-2024 Suomen Kanuuna Oy - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - * - * Additional permission under GNU Affero General Public License version 3 - * section 7 - * - * If you modify this Program, or any covered work, by linking or combining it - * with other code, such other code is not for that reason alone subject to any - * of the requirements of the GNU Affero GPL version 3 as long as this Program - * is the same Program as licensed from Suomen Kanuuna Oy without any additional - * modifications. - * - * Supplemented terms under GNU Affero General Public License version 3 - * section 7 - * - * Origin of the software must be attributed to Suomen Kanuuna Oy. Any modified - * versions must be marked as "Modified version of" The Program. - * - * Names of the licensors and authors may not be used for publicity purposes. - * - * No rights are granted for use of trade names, trademarks, or service marks - * which are in The Program if any. - * - * Licensee must indemnify licensors and authors for any liability that these - * contractual assumptions impose on licensors and authors. - * - * To the extent this program is licensed as part of the Commercial versions of - * Teragrep, the applicable Commercial License may apply to this file if you as - * a licensee so wish it. - */ -package com.teragrep.pth10.steps.teragrep.bloomfilter; - -import org.apache.spark.util.sketch.BloomFilter; -import org.apache.spark.util.sketch.IncompatibleMergeException; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Objects; - -/** - * BloomFilter from byte[] used in a constructor of TeragrepBloomFilter - * - * @see TeragrepBloomFilter - */ -public final class ToBloomFilter extends BloomFilter { - - private final byte[] bytes; - private final List cache; - - public ToBloomFilter(byte[] bytes) { - super(); - this.bytes = bytes; - this.cache = new ArrayList<>(); - } - - private BloomFilter fromBytes() { - // cache used to keep just one instance of the BloomFilter impl - if (cache.isEmpty()) { - final BloomFilter filter; - try (ByteArrayInputStream bais = new ByteArrayInputStream(bytes)) { - filter = BloomFilter.readFrom(bais); - } - catch (IOException e) { - throw new RuntimeException("Error reading bytes to filter: " + e.getMessage()); - } - cache.add(filter); - } - return cache.get(0); - } - - @Override - public double expectedFpp() { - return fromBytes().expectedFpp(); - } - - @Override - public long bitSize() { - return fromBytes().bitSize(); - } - - @Override - public boolean put(final Object item) { - return fromBytes().put(item); - } - - @Override - public boolean putString(final String item) { - return fromBytes().putString(item); - } - - @Override - public boolean putLong(final long item) { - return fromBytes().putLong(item); - } - - @Override - public boolean putBinary(final byte[] item) { - return fromBytes().putBinary(item); - } - - @Override - public boolean isCompatible(final BloomFilter other) { - if (other.getClass() == this.getClass()) { - final ToBloomFilter cast = (ToBloomFilter) other; - return fromBytes().isCompatible(cast.fromBytes()); - } - return fromBytes().isCompatible(other); - } - - @Override - public BloomFilter mergeInPlace(final BloomFilter other) throws IncompatibleMergeException { - if (other.getClass() == this.getClass()) { - final ToBloomFilter cast = (ToBloomFilter) other; - return fromBytes().mergeInPlace(cast.fromBytes()); - } - return fromBytes().mergeInPlace(other); - } - - @Override - public BloomFilter intersectInPlace(final BloomFilter other) throws IncompatibleMergeException { - if (other.getClass() == this.getClass()) { - final ToBloomFilter cast = (ToBloomFilter) other; - return fromBytes().intersectInPlace(cast.fromBytes()); - } - return fromBytes().intersectInPlace(other); - } - - @Override - public boolean mightContain(final Object item) { - return fromBytes().mightContain(item); - } - - @Override - public boolean mightContainString(final String item) { - return fromBytes().mightContainString(item); - } - - @Override - public boolean mightContainLong(final long item) { - return fromBytes().mightContainLong(item); - } - - @Override - public boolean mightContainBinary(final byte[] item) { - return fromBytes().mightContainBinary(item); - } - - @Override - public void writeTo(final OutputStream out) throws IOException { - fromBytes().writeTo(out); - } - - @Override - public boolean equals(final Object object) { - if (this == object) - return true; - if (object == null) - return false; - if (object.getClass() != this.getClass()) - return false; - final ToBloomFilter cast = (ToBloomFilter) object; - return Arrays.equals(this.bytes, cast.bytes); - } - - @Override - public int hashCode() { - return Objects.hash(Arrays.hashCode(bytes), cache); - } -} diff --git a/src/test/java/com/teragrep/pth10/steps/teragrep/bloomfilter/ToBloomFilterTest.java b/src/test/java/com/teragrep/pth10/steps/teragrep/bloomfilter/BloomFilterBlobTest.java similarity index 82% rename from src/test/java/com/teragrep/pth10/steps/teragrep/bloomfilter/ToBloomFilterTest.java rename to src/test/java/com/teragrep/pth10/steps/teragrep/bloomfilter/BloomFilterBlobTest.java index d9440517..c8bd4a9a 100644 --- a/src/test/java/com/teragrep/pth10/steps/teragrep/bloomfilter/ToBloomFilterTest.java +++ b/src/test/java/com/teragrep/pth10/steps/teragrep/bloomfilter/BloomFilterBlobTest.java @@ -45,6 +45,7 @@ */ package com.teragrep.pth10.steps.teragrep.bloomfilter; +import nl.jqno.equalsverifier.EqualsVerifier; import org.apache.spark.util.sketch.BloomFilter; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -54,7 +55,7 @@ import java.util.Arrays; import java.util.List; -class ToBloomFilterTest { +public class BloomFilterBlobTest { private final List tokens = new ArrayList<>(Arrays.asList("one", "two")); private final byte[] bytes = Assertions.assertDoesNotThrow(() -> { @@ -69,14 +70,14 @@ class ToBloomFilterTest { @Test void testCreation() { - Assertions.assertDoesNotThrow(() -> new ToBloomFilter(bytes)); + Assertions.assertDoesNotThrow(() -> new BloomFilterBlob(bytes)); } @Test void testIsCompatible() { - ToBloomFilter filter = new ToBloomFilter(bytes); + BloomFilter filter = new BloomFilterBlob(bytes).toBloomFilter(); Assertions.assertTrue(filter.isCompatible(BloomFilter.create(1000, 0.01))); - Assertions.assertTrue(filter.isCompatible(new ToBloomFilter(bytes))); + Assertions.assertTrue(filter.isCompatible(new BloomFilterBlob(bytes).toBloomFilter())); } @Test @@ -91,8 +92,8 @@ void testMerge() { }); return baos.toByteArray(); }); - ToBloomFilter filter = new ToBloomFilter(bytes); - ToBloomFilter secondFilter = new ToBloomFilter(secondBytes); + BloomFilter filter = new BloomFilterBlob(bytes).toBloomFilter(); + BloomFilter secondFilter = new BloomFilterBlob(secondBytes).toBloomFilter(); Assertions.assertTrue(filter.mightContain("one")); Assertions.assertFalse(filter.mightContain("three")); Assertions.assertTrue(secondFilter.mightContain("three")); @@ -113,10 +114,10 @@ void testIntersectInPlace() { }); return baos.toByteArray(); }); - ToBloomFilter filter = new ToBloomFilter(bytes); + BloomFilter filter = new BloomFilterBlob(bytes).toBloomFilter(); Assertions.assertTrue(filter.mightContain("one")); Assertions.assertTrue(filter.mightContain("two")); - ToBloomFilter secondFilter = new ToBloomFilter(secondBytes); + BloomFilter secondFilter = new BloomFilterBlob(secondBytes).toBloomFilter(); Assertions.assertDoesNotThrow(() -> filter.intersectInPlace(secondFilter)); Assertions.assertTrue(filter.mightContain("two")); Assertions.assertFalse(filter.mightContain("one")); @@ -125,14 +126,14 @@ void testIntersectInPlace() { @Test void testEquality() { - Assertions.assertEquals(new ToBloomFilter(bytes), new ToBloomFilter(bytes)); + Assertions.assertEquals(new BloomFilterBlob(bytes), new BloomFilterBlob(bytes)); } @Test void testEqualityCacheFilled() { - ToBloomFilter filter = new ToBloomFilter(bytes); - Assertions.assertTrue(filter.mightContain("one")); - Assertions.assertEquals(new ToBloomFilter(bytes), filter); + BloomFilterBlob filter = new BloomFilterBlob(bytes); + Assertions.assertTrue(filter.toBloomFilter().mightContain("one")); + Assertions.assertEquals(new BloomFilterBlob(bytes), filter); } @Test @@ -147,6 +148,11 @@ void testNotEquals() { }); return baos.toByteArray(); }); - Assertions.assertNotEquals(new ToBloomFilter(bytes), new ToBloomFilter(secondBytes)); + Assertions.assertNotEquals(new BloomFilterBlob(bytes), new BloomFilterBlob(secondBytes)); + } + + @Test + void testEqualsVerifier() { + EqualsVerifier.forClass(BloomFilterBlob.class).withNonnullFields("bytes").verify(); } } diff --git a/src/test/java/com/teragrep/pth10/steps/teragrep/bloomfilter/BloomFilterForeachPartitionFunctionTest.java b/src/test/java/com/teragrep/pth10/steps/teragrep/bloomfilter/BloomFilterForeachPartitionFunctionTest.java new file mode 100644 index 00000000..9e46310a --- /dev/null +++ b/src/test/java/com/teragrep/pth10/steps/teragrep/bloomfilter/BloomFilterForeachPartitionFunctionTest.java @@ -0,0 +1,60 @@ +/* + * Teragrep Data Processing Language (DPL) translator for Apache Spark (pth_10) + * Copyright (C) 2019-2024 Suomen Kanuuna Oy + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + * + * Additional permission under GNU Affero General Public License version 3 + * section 7 + * + * If you modify this Program, or any covered work, by linking or combining it + * with other code, such other code is not for that reason alone subject to any + * of the requirements of the GNU Affero GPL version 3 as long as this Program + * is the same Program as licensed from Suomen Kanuuna Oy without any additional + * modifications. + * + * Supplemented terms under GNU Affero General Public License version 3 + * section 7 + * + * Origin of the software must be attributed to Suomen Kanuuna Oy. Any modified + * versions must be marked as "Modified version of" The Program. + * + * Names of the licensors and authors may not be used for publicity purposes. + * + * No rights are granted for use of trade names, trademarks, or service marks + * which are in The Program if any. + * + * Licensee must indemnify licensors and authors for any liability that these + * contractual assumptions impose on licensors and authors. + * + * To the extent this program is licensed as part of the Commercial versions of + * Teragrep, the applicable Commercial License may apply to this file if you as + * a licensee so wish it. + */ +package com.teragrep.pth10.steps.teragrep.bloomfilter; + +import nl.jqno.equalsverifier.EqualsVerifier; +import org.junit.jupiter.api.Test; + +public class BloomFilterForeachPartitionFunctionTest { + + @Test + public void testEqualsVerifier() { + EqualsVerifier + .forClass(BloomFilterForeachPartitionFunction.class) + .withNonnullFields("filterTypes", "lazyConnection", "overwrite", "tableName", "regex") + .verify(); + } +} diff --git a/src/test/java/com/teragrep/pth10/steps/teragrep/bloomfilter/BloomFilterTableTest.java b/src/test/java/com/teragrep/pth10/steps/teragrep/bloomfilter/BloomFilterTableTest.java index 36d60b02..bddacc30 100644 --- a/src/test/java/com/teragrep/pth10/steps/teragrep/bloomfilter/BloomFilterTableTest.java +++ b/src/test/java/com/teragrep/pth10/steps/teragrep/bloomfilter/BloomFilterTableTest.java @@ -47,6 +47,7 @@ import com.typesafe.config.Config; import com.typesafe.config.ConfigFactory; +import nl.jqno.equalsverifier.EqualsVerifier; import org.junit.jupiter.api.*; import java.sql.Connection; @@ -182,6 +183,11 @@ void testNotEqualsIgnoreConstraints() { Assertions.assertNotEquals(table1, table2); } + @Test + void testEqualsVerifier() { + EqualsVerifier.forClass(BloomFilterTable.class).withNonnullFields("tableSQL", "conn").verify(); + } + private Properties getDefaultProperties() { final Properties properties = new Properties(); properties.put("dpl.pth_10.bloom.db.username", username); diff --git a/src/test/java/com/teragrep/pth10/steps/teragrep/bloomfilter/FilterTypesTest.java b/src/test/java/com/teragrep/pth10/steps/teragrep/bloomfilter/FilterTypesTest.java index 8c7e048b..ebdd840b 100644 --- a/src/test/java/com/teragrep/pth10/steps/teragrep/bloomfilter/FilterTypesTest.java +++ b/src/test/java/com/teragrep/pth10/steps/teragrep/bloomfilter/FilterTypesTest.java @@ -47,6 +47,7 @@ import com.typesafe.config.Config; import com.typesafe.config.ConfigFactory; +import nl.jqno.equalsverifier.EqualsVerifier; import org.apache.spark.util.sketch.BloomFilter; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; @@ -170,6 +171,11 @@ public void testNotEquals() { assertNotEquals(filterTypes1, filterTypes2); } + @Test + public void testEqualsVerifier() { + EqualsVerifier.forClass(FilterTypes.class).withNonnullFields("config").verify(); + } + public Properties defaultProperties() { Properties properties = new Properties(); properties.put("dpl.pth_10.bloom.db.username", username); diff --git a/src/test/java/com/teragrep/pth10/steps/teragrep/bloomfilter/JournalDBNameFromConfigTest.java b/src/test/java/com/teragrep/pth10/steps/teragrep/bloomfilter/JournalDBNameFromConfigTest.java new file mode 100644 index 00000000..5ced954f --- /dev/null +++ b/src/test/java/com/teragrep/pth10/steps/teragrep/bloomfilter/JournalDBNameFromConfigTest.java @@ -0,0 +1,57 @@ +/* + * Teragrep Data Processing Language (DPL) translator for Apache Spark (pth_10) + * Copyright (C) 2019-2024 Suomen Kanuuna Oy + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + * + * Additional permission under GNU Affero General Public License version 3 + * section 7 + * + * If you modify this Program, or any covered work, by linking or combining it + * with other code, such other code is not for that reason alone subject to any + * of the requirements of the GNU Affero GPL version 3 as long as this Program + * is the same Program as licensed from Suomen Kanuuna Oy without any additional + * modifications. + * + * Supplemented terms under GNU Affero General Public License version 3 + * section 7 + * + * Origin of the software must be attributed to Suomen Kanuuna Oy. Any modified + * versions must be marked as "Modified version of" The Program. + * + * Names of the licensors and authors may not be used for publicity purposes. + * + * No rights are granted for use of trade names, trademarks, or service marks + * which are in The Program if any. + * + * Licensee must indemnify licensors and authors for any liability that these + * contractual assumptions impose on licensors and authors. + * + * To the extent this program is licensed as part of the Commercial versions of + * Teragrep, the applicable Commercial License may apply to this file if you as + * a licensee so wish it. + */ +package com.teragrep.pth10.steps.teragrep.bloomfilter; + +import nl.jqno.equalsverifier.EqualsVerifier; +import org.junit.jupiter.api.Test; + +public class JournalDBNameFromConfigTest { + + @Test + public void testEqualsVerifier() { + EqualsVerifier.forClass(JournalDBNameFromConfig.class).withNonnullFields("config").verify(); + } +} diff --git a/src/test/java/com/teragrep/pth10/steps/teragrep/bloomfilter/LazyConnectionTest.java b/src/test/java/com/teragrep/pth10/steps/teragrep/bloomfilter/LazyConnectionTest.java new file mode 100644 index 00000000..fc45f8bf --- /dev/null +++ b/src/test/java/com/teragrep/pth10/steps/teragrep/bloomfilter/LazyConnectionTest.java @@ -0,0 +1,57 @@ +/* + * Teragrep Data Processing Language (DPL) translator for Apache Spark (pth_10) + * Copyright (C) 2019-2024 Suomen Kanuuna Oy + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + * + * Additional permission under GNU Affero General Public License version 3 + * section 7 + * + * If you modify this Program, or any covered work, by linking or combining it + * with other code, such other code is not for that reason alone subject to any + * of the requirements of the GNU Affero GPL version 3 as long as this Program + * is the same Program as licensed from Suomen Kanuuna Oy without any additional + * modifications. + * + * Supplemented terms under GNU Affero General Public License version 3 + * section 7 + * + * Origin of the software must be attributed to Suomen Kanuuna Oy. Any modified + * versions must be marked as "Modified version of" The Program. + * + * Names of the licensors and authors may not be used for publicity purposes. + * + * No rights are granted for use of trade names, trademarks, or service marks + * which are in The Program if any. + * + * Licensee must indemnify licensors and authors for any liability that these + * contractual assumptions impose on licensors and authors. + * + * To the extent this program is licensed as part of the Commercial versions of + * Teragrep, the applicable Commercial License may apply to this file if you as + * a licensee so wish it. + */ +package com.teragrep.pth10.steps.teragrep.bloomfilter; + +import nl.jqno.equalsverifier.EqualsVerifier; +import org.junit.jupiter.api.Test; + +public class LazyConnectionTest { + + @Test + public void testEqualsVerifier() { + EqualsVerifier.forClass(LazyConnection.class).withNonnullFields("config").verify(); + } +} diff --git a/src/test/java/com/teragrep/pth10/steps/teragrep/bloomfilter/TableSQLTest.java b/src/test/java/com/teragrep/pth10/steps/teragrep/bloomfilter/TableSQLTest.java index a4ee6aa0..546e4aa7 100644 --- a/src/test/java/com/teragrep/pth10/steps/teragrep/bloomfilter/TableSQLTest.java +++ b/src/test/java/com/teragrep/pth10/steps/teragrep/bloomfilter/TableSQLTest.java @@ -45,6 +45,7 @@ */ package com.teragrep.pth10.steps.teragrep.bloomfilter; +import nl.jqno.equalsverifier.EqualsVerifier; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -165,4 +166,12 @@ public void testNotEqualIgnoreConstraints() { TableSQL table2 = new TableSQL("table_2"); Assertions.assertNotEquals(table1, table2); } + + @Test + public void testEqualsVerifier() { + EqualsVerifier + .forClass(TableSQL.class) + .withNonnullFields("validPattern", "name", "journalDBName", "ignoreConstraints") + .verify(); + } } diff --git a/src/test/java/com/teragrep/pth10/steps/teragrep/bloomfilter/TeragrepBloomFilterTest.java b/src/test/java/com/teragrep/pth10/steps/teragrep/bloomfilter/TeragrepBloomFilterTest.java index d2c83067..e46e714c 100644 --- a/src/test/java/com/teragrep/pth10/steps/teragrep/bloomfilter/TeragrepBloomFilterTest.java +++ b/src/test/java/com/teragrep/pth10/steps/teragrep/bloomfilter/TeragrepBloomFilterTest.java @@ -47,6 +47,7 @@ import com.typesafe.config.Config; import com.typesafe.config.ConfigFactory; +import nl.jqno.equalsverifier.EqualsVerifier; import org.apache.spark.sql.Row; import org.apache.spark.sql.RowFactory; import org.apache.spark.util.sketch.BloomFilter; @@ -365,6 +366,14 @@ public void testNotEqualsTokens() { Assertions.assertNotEquals(filter1, filter2); } + @Test + public void testEqualsVerifier() { + EqualsVerifier + .forClass(TeragrepBloomFilter.class) + .withNonnullFields("partitionID", "filter", "connection", "filterTypes", "tableName", "regex") + .verify(); + } + // -- Helper methods -- private Row generatedRow(SortedMap filterMap, List tokens) {