mmiklavc 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_r287025287
 
 

 ##########
 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:
   See my other recent comments on this - can we setup some sensible defaults 
for the config? I think the pattern we've attempted to follow is to maximize 
configurability of the system by exposing as many options as possible, but also 
making easy to get up and running with some defaults that they can configure 
PRN. I'd look at the cache used in `ParallelEnricher` to see what has been used 
for defaults in other caches.

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to