|  | 
|  | 1 | +/* | 
|  | 2 | + * Licensed to the Apache Software Foundation (ASF) under one | 
|  | 3 | + * or more contributor license agreements.  See the NOTICE file | 
|  | 4 | + * distributed with this work for additional information | 
|  | 5 | + * regarding copyright ownership.  The ASF licenses this file | 
|  | 6 | + * to you under the Apache License, Version 2.0 (the | 
|  | 7 | + * "License"); you may not use this file except in compliance | 
|  | 8 | + * with the License.  You may obtain a copy of the License at | 
|  | 9 | + * | 
|  | 10 | + *     http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 11 | + * | 
|  | 12 | + * Unless required by applicable law or agreed to in writing, software | 
|  | 13 | + * distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 15 | + * See the License for the specific language governing permissions and | 
|  | 16 | + * limitations under the License. | 
|  | 17 | + */ | 
|  | 18 | + | 
|  | 19 | +package org.apache.hadoop.fs.statistics.impl; | 
|  | 20 | + | 
|  | 21 | +import java.util.Map; | 
|  | 22 | + | 
|  | 23 | +import org.assertj.core.api.Assertions; | 
|  | 24 | +import org.junit.jupiter.api.Test; | 
|  | 25 | + | 
|  | 26 | +import org.apache.hadoop.test.AbstractHadoopTestBase; | 
|  | 27 | + | 
|  | 28 | +import static org.assertj.core.api.Assertions.assertThat; | 
|  | 29 | + | 
|  | 30 | +public class TestEvaluatingStatisticsMap extends AbstractHadoopTestBase { | 
|  | 31 | + | 
|  | 32 | + | 
|  | 33 | +  @Test | 
|  | 34 | +  public void testEvaluatingStatisticsMap() { | 
|  | 35 | +    EvaluatingStatisticsMap<String> map = new EvaluatingStatisticsMap<>(); | 
|  | 36 | + | 
|  | 37 | +    Assertions.assertThat(map).isEmpty(); | 
|  | 38 | +    Assertions.assertThat(map.keySet()).isEmpty(); | 
|  | 39 | +    Assertions.assertThat(map.values()).isEmpty(); | 
|  | 40 | +    Assertions.assertThat(map.entrySet()).isEmpty(); | 
|  | 41 | + | 
|  | 42 | +    // fill the map with the environment vars | 
|  | 43 | +    final Map<String, String> env = System.getenv(); | 
|  | 44 | +    env.forEach((k, v) -> map.addFunction(k, any -> v)); | 
|  | 45 | + | 
|  | 46 | +    // verify the keys match | 
|  | 47 | +    assertThat(map.keySet()) | 
|  | 48 | +        .describedAs("keys") | 
|  | 49 | +        .containsExactlyInAnyOrderElementsOf(env.keySet()); | 
|  | 50 | + | 
|  | 51 | +    // and that the values do | 
|  | 52 | +    assertThat(map.values()) | 
|  | 53 | +        .describedAs("Evaluated values") | 
|  | 54 | +        .containsExactlyInAnyOrderElementsOf(env.values()); | 
|  | 55 | + | 
|  | 56 | +    // now assert that this holds for the entryset. | 
|  | 57 | +    env.forEach((k, v) -> | 
|  | 58 | +        assertThat(map.get(k)) | 
|  | 59 | +            .describedAs("looked up key %s", k) | 
|  | 60 | +            .isNotNull() | 
|  | 61 | +            .isEqualTo(v)); | 
|  | 62 | + | 
|  | 63 | +    map.forEach((k, v) -> | 
|  | 64 | +        assertThat(env.get(k)) | 
|  | 65 | +            .describedAs("env var %s", k) | 
|  | 66 | +            .isNotNull() | 
|  | 67 | +            .isEqualTo(v)); | 
|  | 68 | + | 
|  | 69 | + | 
|  | 70 | +  } | 
|  | 71 | +} | 
0 commit comments