ctubbsii commented on code in PR #3676:
URL: https://github.com/apache/accumulo/pull/3676#discussion_r1282470904


##########
server/base/src/test/java/org/apache/accumulo/server/conf/AccumuloConfigurationIsPropertySetTest.java:
##########
@@ -0,0 +1,327 @@
+/*
+ * 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
+ *
+ *   https://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.accumulo.server.conf;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.apache.accumulo.core.conf.Property.GC_PORT;
+import static org.apache.accumulo.core.conf.Property.INSTANCE_SECRET;
+import static org.apache.accumulo.core.conf.Property.INSTANCE_ZK_HOST;
+import static 
org.apache.accumulo.core.conf.Property.MANAGER_BULK_TSERVER_REGEX;
+import static org.apache.accumulo.core.conf.Property.TABLE_BLOOM_ENABLED;
+import static org.apache.accumulo.core.conf.Property.TABLE_BLOOM_SIZE;
+import static org.apache.accumulo.core.conf.Property.TABLE_DURABILITY;
+import static org.apache.accumulo.core.conf.Property.TABLE_FILE_MAX;
+import static org.apache.accumulo.core.conf.Property.TSERV_SCAN_MAX_OPENFILES;
+import static 
org.apache.accumulo.server.MockServerContext.getMockContextWithPropStore;
+import static org.easymock.EasyMock.anyObject;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.eq;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.reset;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.time.Instant;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+
+import org.apache.accumulo.core.conf.AccumuloConfiguration;
+import org.apache.accumulo.core.conf.ConfigurationCopy;
+import org.apache.accumulo.core.conf.DefaultConfiguration;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.conf.SiteConfiguration;
+import org.apache.accumulo.core.data.InstanceId;
+import org.apache.accumulo.core.data.NamespaceId;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.fate.zookeeper.ZooReaderWriter;
+import org.apache.accumulo.server.ServerContext;
+import org.apache.accumulo.server.WithTestNames;
+import org.apache.accumulo.server.conf.codec.VersionedProperties;
+import org.apache.accumulo.server.conf.store.NamespacePropKey;
+import org.apache.accumulo.server.conf.store.PropStore;
+import org.apache.accumulo.server.conf.store.SystemPropKey;
+import org.apache.accumulo.server.conf.store.TablePropKey;
+import org.apache.accumulo.server.conf.store.impl.ZooPropStore;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.collect.Sets;
+
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+
+/**
+ * Ensure that each implementation of AccumuloConfiguration has a working 
implementation of
+ * isPropertySet()
+ */
+public class AccumuloConfigurationIsPropertySetTest extends WithTestNames {
+
+  private static final Set<Property> ALL_PROPERTIES =
+      Arrays.stream(Property.values()).collect(Collectors.toSet());
+  private static final Logger log =
+      LoggerFactory.getLogger(AccumuloConfigurationIsPropertySetTest.class);
+
+  @TempDir
+  private static File tempDir;
+
+  /**
+   * Test that the provided properties are set or not set using
+   * {@link AccumuloConfiguration#isPropertySet(Property)}
+   *
+   * @param accumuloConfiguration impl to test against
+   * @param expectIsSet set of props that should be set
+   * @param expectNotSet set of props that should not be set
+   */
+  private static void testPropertyIsSetImpl(AccumuloConfiguration 
accumuloConfiguration,
+      Set<Property> expectIsSet, Set<Property> expectNotSet) {
+    for (Property prop : expectIsSet) {
+      assertTrue(accumuloConfiguration.isPropertySet(prop), "Expected " + prop 
+ " to be set");
+    }
+    for (Property prop : expectNotSet) {
+      assertFalse(accumuloConfiguration.isPropertySet(prop), "Expected " + 
prop + " to NOT be set");
+    }
+  }
+
+  /**
+   * Verifies that the expected properties are in the given config object 
without using
+   * isPropertySet
+   */
+  private static void verifyProps(AccumuloConfiguration accumuloConfiguration,
+      Set<Property> shouldBeSet, Set<Property> shouldNotBeSet) {
+    Map<String,String> propsMap = new HashMap<>();
+    accumuloConfiguration.getProperties(propsMap, x -> true);
+    Predicate<Property> mapContainsProp = property -> 
propsMap.containsKey(property.getKey());
+    assertTrue(shouldBeSet.stream().allMatch(mapContainsProp));
+    assertTrue(shouldNotBeSet.stream().noneMatch(mapContainsProp));
+  }
+
+  @Test
+  public void configurationCopy() {
+    Set<Property> shouldBeSet = Set.of(TABLE_BLOOM_SIZE, GC_PORT);
+    Set<Property> shouldNotBeSet = Sets.difference(shouldBeSet, 
ALL_PROPERTIES);

Review Comment:
   I think you have the parameters to `Sets.difference` backwards. This will 
show `shouldBeSet - ALL_PROPERTIES = EMPTY_SET`.
   
   You should probably add asserts to make sure the difference is not empty, to 
avoid that kind of bug in the test code.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to