From a39f1eadb7e568eb48a5c108680631b1df3fd1ec Mon Sep 17 00:00:00 2001 From: Dongjoon Hyun Date: Sat, 19 Jun 2021 11:36:01 -0700 Subject: [PATCH] [SPARK-35824][CORE][TESTS] Convert LevelDBSuite.IntKeyType from a nested class to a normal class ### What changes were proposed in this pull request? This PR aims to promote `LevelDBSuite.IntKeyType` class to a normal class to isolate `InMemoryIteratorSuite` from `LevelDBSuite`. ### Why are the changes needed? We have the following test suite hierarchy. ``` DBIteratorSuite - InMemoryIteratorSuite - LevelDBIteratorSuite ``` `DBIteratorSuite.testRefWithIntNaturalKey` depends on `LevelDBSuite` and `InMemoryIteratorSuite` derived it. `InMemoryIteratorSuite` should not depend not `LevelDB`-specific stuff. This PR will make it sure. ``` public void testRefWithIntNaturalKey() throws Exception { LevelDBSuite.IntKeyType i = new LevelDBSuite.IntKeyType(); ... ``` ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? Pass the CIs. ``` $ build/sbt "kvstore/test" ``` Closes #32971 from dongjoon-hyun/SPARK-35824. Authored-by: Dongjoon Hyun Signed-off-by: Dongjoon Hyun --- .../spark/util/kvstore/DBIteratorSuite.java | 2 +- .../apache/spark/util/kvstore/IntKeyType.java | 47 +++++++++++++++++++ .../spark/util/kvstore/LevelDBSuite.java | 27 ----------- 3 files changed, 48 insertions(+), 28 deletions(-) create mode 100644 common/kvstore/src/test/java/org/apache/spark/util/kvstore/IntKeyType.java diff --git a/common/kvstore/src/test/java/org/apache/spark/util/kvstore/DBIteratorSuite.java b/common/kvstore/src/test/java/org/apache/spark/util/kvstore/DBIteratorSuite.java index 1e062437d1..e9a671d65d 100644 --- a/common/kvstore/src/test/java/org/apache/spark/util/kvstore/DBIteratorSuite.java +++ b/common/kvstore/src/test/java/org/apache/spark/util/kvstore/DBIteratorSuite.java @@ -380,7 +380,7 @@ public abstract class DBIteratorSuite { @Test public void testRefWithIntNaturalKey() throws Exception { - LevelDBSuite.IntKeyType i = new LevelDBSuite.IntKeyType(); + IntKeyType i = new IntKeyType(); i.key = 1; i.id = "1"; i.values = Arrays.asList("1"); diff --git a/common/kvstore/src/test/java/org/apache/spark/util/kvstore/IntKeyType.java b/common/kvstore/src/test/java/org/apache/spark/util/kvstore/IntKeyType.java new file mode 100644 index 0000000000..f7051246f7 --- /dev/null +++ b/common/kvstore/src/test/java/org/apache/spark/util/kvstore/IntKeyType.java @@ -0,0 +1,47 @@ +/* + * 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.spark.util.kvstore; + +import java.util.List; + +public class IntKeyType { + + @KVIndex + public int key; + + @KVIndex("id") + public String id; + + public List values; + + @Override + public boolean equals(Object o) { + if (o instanceof IntKeyType) { + IntKeyType other = (IntKeyType) o; + return key == other.key && id.equals(other.id) && values.equals(other.values); + } + return false; + } + + @Override + public int hashCode() { + return id.hashCode(); + } + +} + diff --git a/common/kvstore/src/test/java/org/apache/spark/util/kvstore/LevelDBSuite.java b/common/kvstore/src/test/java/org/apache/spark/util/kvstore/LevelDBSuite.java index f656661776..f031a41770 100644 --- a/common/kvstore/src/test/java/org/apache/spark/util/kvstore/LevelDBSuite.java +++ b/common/kvstore/src/test/java/org/apache/spark/util/kvstore/LevelDBSuite.java @@ -338,31 +338,4 @@ public class LevelDBSuite { return count; } - - public static class IntKeyType { - - @KVIndex - public int key; - - @KVIndex("id") - public String id; - - public List values; - - @Override - public boolean equals(Object o) { - if (o instanceof IntKeyType) { - IntKeyType other = (IntKeyType) o; - return key == other.key && id.equals(other.id) && values.equals(other.values); - } - return false; - } - - @Override - public int hashCode() { - return id.hashCode(); - } - - } - }