From 9e73640e1a4d3c29330b72101efde051f6284a57 Mon Sep 17 00:00:00 2001
From: Rasmus Jokinen <146736881+51-code@users.noreply.github.com>
Date: Thu, 5 Dec 2024 12:02:14 +0200
Subject: [PATCH 1/3] Add equals tests to BloomFilter classes, rename
ModeFromBloomContext, refactor ToBloomFilter
---
pom.xml | 6 +
.../TeragrepTransformation.java | 4 +-
...loomContext.java => ContextBloomMode.java} | 4 +-
.../BloomFilterForeachPartitionFunction.java | 15 +++
.../bloomfilter/TeragrepBloomFilter.java | 2 +-
.../teragrep/bloomfilter/ToBloomFilter.java | 114 ++----------------
...oomFilterForeachPartitionFunctionTest.java | 59 +++++++++
.../bloomfilter/BloomFilterTableTest.java | 6 +
.../teragrep/bloomfilter/FilterTypesTest.java | 6 +
.../JournalDBNameFromConfigTest.java | 57 +++++++++
.../bloomfilter/LazyConnectionTest.java | 57 +++++++++
.../teragrep/bloomfilter/TableSQLTest.java | 9 ++
.../bloomfilter/TeragrepBloomFilterTest.java | 8 ++
.../bloomfilter/ToBloomFilterTest.java | 22 ++--
14 files changed, 252 insertions(+), 117 deletions(-)
rename src/main/java/com/teragrep/pth10/ast/commands/transformstatement/teragrep/{ModeFromBloomContext.java => ContextBloomMode.java} (94%)
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 badeb601..05b4fd26 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/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..129d48dd 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 ToBloomFilter(bytes).fromBytes(), 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
index 1e4b5208..79731ad2 100644
--- a/src/main/java/com/teragrep/pth10/steps/teragrep/bloomfilter/ToBloomFilter.java
+++ b/src/main/java/com/teragrep/pth10/steps/teragrep/bloomfilter/ToBloomFilter.java
@@ -46,127 +46,33 @@
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 {
+public final class ToBloomFilter {
private final byte[] bytes;
- private final List cache;
- public ToBloomFilter(byte[] bytes) {
- super();
+ public ToBloomFilter(final byte[] bytes) {
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);
+ public BloomFilter fromBytes() {
+ final BloomFilter filter;
+ try (ByteArrayInputStream bais = new ByteArrayInputStream(bytes)) {
+ filter = BloomFilter.readFrom(bais);
}
- 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());
+ catch (IOException e) {
+ throw new RuntimeException("Error reading bytes to filter: " + e.getMessage());
}
- 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);
+ return filter;
}
@Override
@@ -183,6 +89,6 @@ public boolean equals(final Object object) {
@Override
public int hashCode() {
- return Objects.hash(Arrays.hashCode(bytes), cache);
+ return Arrays.hashCode(bytes);
}
}
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..cc17f05c
--- /dev/null
+++ b/src/test/java/com/teragrep/pth10/steps/teragrep/bloomfilter/BloomFilterForeachPartitionFunctionTest.java
@@ -0,0 +1,59 @@
+/*
+ * 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");
+ }
+}
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..3f4e23ea 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,13 @@ public void testNotEqualsTokens() {
Assertions.assertNotEquals(filter1, filter2);
}
+ @Test
+ public void testEqualsVerifier() {
+ EqualsVerifier
+ .forClass(TeragrepBloomFilter.class)
+ .withNonnullFields("partitionID", "filter", "connection", "filterTypes", "tableName", "regex");
+ }
+
// -- Helper methods --
private Row generatedRow(SortedMap filterMap, List tokens) {
diff --git a/src/test/java/com/teragrep/pth10/steps/teragrep/bloomfilter/ToBloomFilterTest.java b/src/test/java/com/teragrep/pth10/steps/teragrep/bloomfilter/ToBloomFilterTest.java
index d9440517..4a7d6aec 100644
--- a/src/test/java/com/teragrep/pth10/steps/teragrep/bloomfilter/ToBloomFilterTest.java
+++ b/src/test/java/com/teragrep/pth10/steps/teragrep/bloomfilter/ToBloomFilterTest.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 ToBloomFilterTest {
private final List tokens = new ArrayList<>(Arrays.asList("one", "two"));
private final byte[] bytes = Assertions.assertDoesNotThrow(() -> {
@@ -74,9 +75,9 @@ void testCreation() {
@Test
void testIsCompatible() {
- ToBloomFilter filter = new ToBloomFilter(bytes);
+ BloomFilter filter = new ToBloomFilter(bytes).fromBytes();
Assertions.assertTrue(filter.isCompatible(BloomFilter.create(1000, 0.01)));
- Assertions.assertTrue(filter.isCompatible(new ToBloomFilter(bytes)));
+ Assertions.assertTrue(filter.isCompatible(new ToBloomFilter(bytes).fromBytes()));
}
@Test
@@ -91,8 +92,8 @@ void testMerge() {
});
return baos.toByteArray();
});
- ToBloomFilter filter = new ToBloomFilter(bytes);
- ToBloomFilter secondFilter = new ToBloomFilter(secondBytes);
+ BloomFilter filter = new ToBloomFilter(bytes).fromBytes();
+ BloomFilter secondFilter = new ToBloomFilter(secondBytes).fromBytes();
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 ToBloomFilter(bytes).fromBytes();
Assertions.assertTrue(filter.mightContain("one"));
Assertions.assertTrue(filter.mightContain("two"));
- ToBloomFilter secondFilter = new ToBloomFilter(secondBytes);
+ BloomFilter secondFilter = new ToBloomFilter(secondBytes).fromBytes();
Assertions.assertDoesNotThrow(() -> filter.intersectInPlace(secondFilter));
Assertions.assertTrue(filter.mightContain("two"));
Assertions.assertFalse(filter.mightContain("one"));
@@ -131,7 +132,7 @@ void testEquality() {
@Test
void testEqualityCacheFilled() {
ToBloomFilter filter = new ToBloomFilter(bytes);
- Assertions.assertTrue(filter.mightContain("one"));
+ filter.fromBytes();
Assertions.assertEquals(new ToBloomFilter(bytes), filter);
}
@@ -149,4 +150,9 @@ void testNotEquals() {
});
Assertions.assertNotEquals(new ToBloomFilter(bytes), new ToBloomFilter(secondBytes));
}
+
+ @Test
+ void testEqualsVerifier() {
+ EqualsVerifier.forClass(ToBloomFilter.class).withNonnullFields("bytes").verify();
+ }
}
From 5ee409a3501c38d3c8fb9f472c3fee1650685ec6 Mon Sep 17 00:00:00 2001
From: Rasmus Jokinen <146736881+51-code@users.noreply.github.com>
Date: Mon, 9 Dec 2024 09:08:00 +0200
Subject: [PATCH 2/3] Fix equals tests in BloomFilter classes
---
.../bloomfilter/BloomFilterForeachPartitionFunctionTest.java | 3 ++-
.../steps/teragrep/bloomfilter/TeragrepBloomFilterTest.java | 3 ++-
.../pth10/steps/teragrep/bloomfilter/ToBloomFilterTest.java | 2 +-
3 files changed, 5 insertions(+), 3 deletions(-)
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
index cc17f05c..9e46310a 100644
--- a/src/test/java/com/teragrep/pth10/steps/teragrep/bloomfilter/BloomFilterForeachPartitionFunctionTest.java
+++ b/src/test/java/com/teragrep/pth10/steps/teragrep/bloomfilter/BloomFilterForeachPartitionFunctionTest.java
@@ -54,6 +54,7 @@ public class BloomFilterForeachPartitionFunctionTest {
public void testEqualsVerifier() {
EqualsVerifier
.forClass(BloomFilterForeachPartitionFunction.class)
- .withNonnullFields("filterTypes", "lazyConnection", "overwrite", "tableName", "regex");
+ .withNonnullFields("filterTypes", "lazyConnection", "overwrite", "tableName", "regex")
+ .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 3f4e23ea..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
@@ -370,7 +370,8 @@ public void testNotEqualsTokens() {
public void testEqualsVerifier() {
EqualsVerifier
.forClass(TeragrepBloomFilter.class)
- .withNonnullFields("partitionID", "filter", "connection", "filterTypes", "tableName", "regex");
+ .withNonnullFields("partitionID", "filter", "connection", "filterTypes", "tableName", "regex")
+ .verify();
}
// -- Helper methods --
diff --git a/src/test/java/com/teragrep/pth10/steps/teragrep/bloomfilter/ToBloomFilterTest.java b/src/test/java/com/teragrep/pth10/steps/teragrep/bloomfilter/ToBloomFilterTest.java
index 4a7d6aec..4b0a39de 100644
--- a/src/test/java/com/teragrep/pth10/steps/teragrep/bloomfilter/ToBloomFilterTest.java
+++ b/src/test/java/com/teragrep/pth10/steps/teragrep/bloomfilter/ToBloomFilterTest.java
@@ -132,7 +132,7 @@ void testEquality() {
@Test
void testEqualityCacheFilled() {
ToBloomFilter filter = new ToBloomFilter(bytes);
- filter.fromBytes();
+ Assertions.assertTrue(filter.fromBytes().mightContain("one"));
Assertions.assertEquals(new ToBloomFilter(bytes), filter);
}
From 42afd176eabbf4291d22b34080f375f0f7404523 Mon Sep 17 00:00:00 2001
From: Rasmus Jokinen <146736881+51-code@users.noreply.github.com>
Date: Mon, 9 Dec 2024 12:21:31 +0200
Subject: [PATCH 3/3] Rename ToBloomFilter to BloomFilterBlob
---
...oBloomFilter.java => BloomFilterBlob.java} | 8 +++---
.../bloomfilter/TeragrepBloomFilter.java | 2 +-
...lterTest.java => BloomFilterBlobTest.java} | 28 +++++++++----------
3 files changed, 19 insertions(+), 19 deletions(-)
rename src/main/java/com/teragrep/pth10/steps/teragrep/bloomfilter/{ToBloomFilter.java => BloomFilterBlob.java} (94%)
rename src/test/java/com/teragrep/pth10/steps/teragrep/bloomfilter/{ToBloomFilterTest.java => BloomFilterBlobTest.java} (83%)
diff --git a/src/main/java/com/teragrep/pth10/steps/teragrep/bloomfilter/ToBloomFilter.java b/src/main/java/com/teragrep/pth10/steps/teragrep/bloomfilter/BloomFilterBlob.java
similarity index 94%
rename from src/main/java/com/teragrep/pth10/steps/teragrep/bloomfilter/ToBloomFilter.java
rename to src/main/java/com/teragrep/pth10/steps/teragrep/bloomfilter/BloomFilterBlob.java
index 79731ad2..578d37f9 100644
--- a/src/main/java/com/teragrep/pth10/steps/teragrep/bloomfilter/ToBloomFilter.java
+++ b/src/main/java/com/teragrep/pth10/steps/teragrep/bloomfilter/BloomFilterBlob.java
@@ -56,15 +56,15 @@
*
* @see TeragrepBloomFilter
*/
-public final class ToBloomFilter {
+public final class BloomFilterBlob {
private final byte[] bytes;
- public ToBloomFilter(final byte[] bytes) {
+ public BloomFilterBlob(final byte[] bytes) {
this.bytes = bytes;
}
- public BloomFilter fromBytes() {
+ public BloomFilter toBloomFilter() {
final BloomFilter filter;
try (ByteArrayInputStream bais = new ByteArrayInputStream(bytes)) {
filter = BloomFilter.readFrom(bais);
@@ -83,7 +83,7 @@ public boolean equals(final Object object) {
return false;
if (object.getClass() != this.getClass())
return false;
- final ToBloomFilter cast = (ToBloomFilter) object;
+ final BloomFilterBlob cast = (BloomFilterBlob) object;
return Arrays.equals(this.bytes, cast.bytes);
}
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 129d48dd..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).fromBytes(), connection, filterTypes, tableName, regex);
+ this(partition, new BloomFilterBlob(bytes).toBloomFilter(), connection, filterTypes, tableName, regex);
}
public TeragrepBloomFilter(
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 83%
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 4b0a39de..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
@@ -55,7 +55,7 @@
import java.util.Arrays;
import java.util.List;
-public class ToBloomFilterTest {
+public class BloomFilterBlobTest {
private final List tokens = new ArrayList<>(Arrays.asList("one", "two"));
private final byte[] bytes = Assertions.assertDoesNotThrow(() -> {
@@ -70,14 +70,14 @@ public class ToBloomFilterTest {
@Test
void testCreation() {
- Assertions.assertDoesNotThrow(() -> new ToBloomFilter(bytes));
+ Assertions.assertDoesNotThrow(() -> new BloomFilterBlob(bytes));
}
@Test
void testIsCompatible() {
- BloomFilter filter = new ToBloomFilter(bytes).fromBytes();
+ BloomFilter filter = new BloomFilterBlob(bytes).toBloomFilter();
Assertions.assertTrue(filter.isCompatible(BloomFilter.create(1000, 0.01)));
- Assertions.assertTrue(filter.isCompatible(new ToBloomFilter(bytes).fromBytes()));
+ Assertions.assertTrue(filter.isCompatible(new BloomFilterBlob(bytes).toBloomFilter()));
}
@Test
@@ -92,8 +92,8 @@ void testMerge() {
});
return baos.toByteArray();
});
- BloomFilter filter = new ToBloomFilter(bytes).fromBytes();
- BloomFilter secondFilter = new ToBloomFilter(secondBytes).fromBytes();
+ 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"));
@@ -114,10 +114,10 @@ void testIntersectInPlace() {
});
return baos.toByteArray();
});
- BloomFilter filter = new ToBloomFilter(bytes).fromBytes();
+ BloomFilter filter = new BloomFilterBlob(bytes).toBloomFilter();
Assertions.assertTrue(filter.mightContain("one"));
Assertions.assertTrue(filter.mightContain("two"));
- BloomFilter secondFilter = new ToBloomFilter(secondBytes).fromBytes();
+ BloomFilter secondFilter = new BloomFilterBlob(secondBytes).toBloomFilter();
Assertions.assertDoesNotThrow(() -> filter.intersectInPlace(secondFilter));
Assertions.assertTrue(filter.mightContain("two"));
Assertions.assertFalse(filter.mightContain("one"));
@@ -126,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.fromBytes().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
@@ -148,11 +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(ToBloomFilter.class).withNonnullFields("bytes").verify();
+ EqualsVerifier.forClass(BloomFilterBlob.class).withNonnullFields("bytes").verify();
}
}