merrimanr commented on a change in pull request #1399: METRON-2073: Create 
in-memory use case for enrichment with map type and flatfile summarizer
URL: https://github.com/apache/metron/pull/1399#discussion_r286716947
 
 

 ##########
 File path: 
metron-platform/metron-enrichment/metron-enrichment-common/src/test/java/org/apache/metron/enrichment/cache/ObjectCacheTest.java
 ##########
 @@ -0,0 +1,113 @@
+/**
+ * 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.metron.enrichment.cache;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.metron.common.utils.SerDeUtils;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import java.io.BufferedOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class ObjectCacheTest {
+
+  @Rule
+  public ExpectedException thrown = ExpectedException.none();
+
+  FileSystem fs;
+  List<String> data;
+  ObjectCache cache;
+
+  @Before
+  public void setup() throws IOException {
+    fs = FileSystem.get(new Configuration());
+    data = new ArrayList<>();
+    {
+      data.add("apache");
+      data.add("metron");
+      data.add("is");
+      data.add("great");
+    }
+    cache = new ObjectCache();
+  }
+
+  @Test
+  public void test() throws Exception {
+    String filename = "target/ogt/test.ser";
+    Assert.assertTrue(cache.getCache() == null || 
!cache.getCache().asMap().containsKey(filename));
+    assertDataIsReadCorrectly(filename);
+  }
+
+  public void assertDataIsReadCorrectly(String filename) throws IOException {
+    try(BufferedOutputStream bos = new BufferedOutputStream(fs.create(new 
Path(filename), true))) {
+      IOUtils.write(SerDeUtils.toBytes(data), bos);
+    }
+    cache.initialize(ObjectCacheConfig.fromGlobalConfig(new HashMap<>()));
 
 Review comment:
   You're right.  The no arg constructor doesn't really serve any purpose.  I 
will change `fromGlobalConfig` to a constructor (should have done this in the 
first place).
   
   The NPE comes from Caffeine code.  As long as we're not passing in null 
values to the cache builder it's not an issue. 

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to