metron-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cestella <...@git.apache.org>
Subject [GitHub] metron pull request #880: METRON-1379: Add an OBJECT_GET stellar function
Date Mon, 08 Jan 2018 20:04:14 GMT
Github user cestella commented on a diff in the pull request:

    https://github.com/apache/metron/pull/880#discussion_r160242210
  
    --- Diff: metron-platform/metron-enrichment/src/test/java/org/apache/metron/enrichment/stellar/ObjectGetTest.java
---
    @@ -0,0 +1,91 @@
    +/**
    + * 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.stellar;
    +
    +import com.google.common.collect.ImmutableMap;
    +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.apache.metron.stellar.common.utils.StellarProcessorUtils;
    +import org.junit.Assert;
    +import org.junit.Before;
    +import org.junit.Test;
    +
    +import java.io.BufferedOutputStream;
    +import java.io.IOException;
    +import java.util.ArrayList;
    +import java.util.HashMap;
    +import java.util.List;
    +
    +public class ObjectGetTest {
    +  FileSystem fs;
    +  List<String> data;
    +
    +  @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");
    +    }
    +
    +  }
    +
    +  @Test
    +  public void test() throws Exception {
    +    String filename = "target/ogt/test.ser";
    +    Assert.assertTrue(ObjectGet.cache == null || !ObjectGet.cache.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);
    +      bos.flush();
    --- End diff --
    
    That is not necessarily correct (in general) as Closeable does not enforce flush prior
to close (in fact, it doesn't even know about flush()).  That being said, strictly speaking,
it is not required in this case as it is called for `BufferedOutputStream`.  I have just gotten
into the habit of being explicit in calling flush since it's bitten me in the butt so many
times in the past.  I'm going to take it out in this case as it's not strictly required.


---

Mime
View raw message