You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by tk...@apache.org on 2015/12/02 04:51:14 UTC
[08/24] nifi git commit: NIFI-1054: Fixed DOS line endings in xml,
java and js source files
http://git-wip-us.apache.org/repos/asf/nifi/blob/3a7ddc6a/nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/main/java/org/apache/nifi/provenance/toc/StandardTocWriter.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/main/java/org/apache/nifi/provenance/toc/StandardTocWriter.java b/nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/main/java/org/apache/nifi/provenance/toc/StandardTocWriter.java
index afa5d13..c9278a1 100644
--- a/nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/main/java/org/apache/nifi/provenance/toc/StandardTocWriter.java
+++ b/nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/main/java/org/apache/nifi/provenance/toc/StandardTocWriter.java
@@ -1,120 +1,120 @@
-/*
- * 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.nifi.provenance.toc;
-
-import java.io.BufferedOutputStream;
-import java.io.DataOutputStream;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.nio.file.Files;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Standard implementation of {@link TocWriter}.
- *
- * Format of .toc file:
- * byte 0: version
- * byte 1: compressed: 0 -> not compressed, 1 -> compressed
- * byte 2-9: long: offset of block 0
- * byte 10-17: long: offset of block 1
- * ...
- * byte (N*8+2)-(N*8+9): long: offset of block N
- */
-public class StandardTocWriter implements TocWriter {
- private static final Logger logger = LoggerFactory.getLogger(StandardTocWriter.class);
-
- public static final byte VERSION = 2;
-
- private final File file;
- private final FileOutputStream fos;
- private final boolean alwaysSync;
- private int index = -1;
-
- /**
- * Creates a StandardTocWriter that writes to the given file.
- * @param file the file to write to
- * @param compressionFlag whether or not the journal is compressed
- * @throws IOException if unable to write header info to the specified file
- */
- public StandardTocWriter(final File file, final boolean compressionFlag, final boolean alwaysSync) throws IOException {
- final File tocDir = file.getParentFile();
- if ( !tocDir.exists() ) {
- Files.createDirectories(tocDir.toPath());
- }
-
- this.file = file;
- fos = new FileOutputStream(file);
- this.alwaysSync = alwaysSync;
-
- final byte[] header = new byte[2];
- header[0] = VERSION;
- header[1] = (byte) (compressionFlag ? 1 : 0);
- fos.write(header);
- fos.flush();
-
- if ( alwaysSync ) {
- sync();
- }
- }
-
- @Override
- public void addBlockOffset(final long offset, final long firstEventId) throws IOException {
- final BufferedOutputStream bos = new BufferedOutputStream(fos);
- final DataOutputStream dos = new DataOutputStream(bos);
- dos.writeLong(offset);
- dos.writeLong(firstEventId);
- dos.flush();
- index++;
- logger.debug("Adding block {} at offset {}", index, offset);
-
- if ( alwaysSync ) {
- sync();
- }
- }
-
- @Override
- public void sync() throws IOException {
- fos.getFD().sync();
- }
-
- @Override
- public int getCurrentBlockIndex() {
- return index;
- }
-
- @Override
- public void close() throws IOException {
- if (alwaysSync) {
- fos.getFD().sync();
- }
-
- fos.close();
- }
-
- @Override
- public File getFile() {
- return file;
- }
-
- @Override
- public String toString() {
- return "TOC Writer for " + file;
- }
-}
+/*
+ * 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.nifi.provenance.toc;
+
+import java.io.BufferedOutputStream;
+import java.io.DataOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.nio.file.Files;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Standard implementation of {@link TocWriter}.
+ *
+ * Format of .toc file:
+ * byte 0: version
+ * byte 1: compressed: 0 -> not compressed, 1 -> compressed
+ * byte 2-9: long: offset of block 0
+ * byte 10-17: long: offset of block 1
+ * ...
+ * byte (N*8+2)-(N*8+9): long: offset of block N
+ */
+public class StandardTocWriter implements TocWriter {
+ private static final Logger logger = LoggerFactory.getLogger(StandardTocWriter.class);
+
+ public static final byte VERSION = 2;
+
+ private final File file;
+ private final FileOutputStream fos;
+ private final boolean alwaysSync;
+ private int index = -1;
+
+ /**
+ * Creates a StandardTocWriter that writes to the given file.
+ * @param file the file to write to
+ * @param compressionFlag whether or not the journal is compressed
+ * @throws IOException if unable to write header info to the specified file
+ */
+ public StandardTocWriter(final File file, final boolean compressionFlag, final boolean alwaysSync) throws IOException {
+ final File tocDir = file.getParentFile();
+ if ( !tocDir.exists() ) {
+ Files.createDirectories(tocDir.toPath());
+ }
+
+ this.file = file;
+ fos = new FileOutputStream(file);
+ this.alwaysSync = alwaysSync;
+
+ final byte[] header = new byte[2];
+ header[0] = VERSION;
+ header[1] = (byte) (compressionFlag ? 1 : 0);
+ fos.write(header);
+ fos.flush();
+
+ if ( alwaysSync ) {
+ sync();
+ }
+ }
+
+ @Override
+ public void addBlockOffset(final long offset, final long firstEventId) throws IOException {
+ final BufferedOutputStream bos = new BufferedOutputStream(fos);
+ final DataOutputStream dos = new DataOutputStream(bos);
+ dos.writeLong(offset);
+ dos.writeLong(firstEventId);
+ dos.flush();
+ index++;
+ logger.debug("Adding block {} at offset {}", index, offset);
+
+ if ( alwaysSync ) {
+ sync();
+ }
+ }
+
+ @Override
+ public void sync() throws IOException {
+ fos.getFD().sync();
+ }
+
+ @Override
+ public int getCurrentBlockIndex() {
+ return index;
+ }
+
+ @Override
+ public void close() throws IOException {
+ if (alwaysSync) {
+ fos.getFD().sync();
+ }
+
+ fos.close();
+ }
+
+ @Override
+ public File getFile() {
+ return file;
+ }
+
+ @Override
+ public String toString() {
+ return "TOC Writer for " + file;
+ }
+}
http://git-wip-us.apache.org/repos/asf/nifi/blob/3a7ddc6a/nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/main/java/org/apache/nifi/provenance/toc/TocReader.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/main/java/org/apache/nifi/provenance/toc/TocReader.java b/nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/main/java/org/apache/nifi/provenance/toc/TocReader.java
index f7ddd59..be6a165 100644
--- a/nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/main/java/org/apache/nifi/provenance/toc/TocReader.java
+++ b/nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/main/java/org/apache/nifi/provenance/toc/TocReader.java
@@ -1,71 +1,71 @@
-/*
- * 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.nifi.provenance.toc;
-
-import java.io.Closeable;
-
-/**
- * <p>
- * Reads a Table of Contents (.toc file) for a corresponding Journal File. We use a Table of Contents
- * to map a Block Index to an offset into the Journal file where that Block begins. We do this so that
- * we can then persist a Block Index for an event and then compress the Journal later. This way, we can
- * get good compression by compressing a large batch of events at once, and this way we can also look up
- * an event in a Journal that has not been compressed by looking in the Table of Contents or lookup the
- * event in a Journal post-compression by simply rewriting the TOC while we compress the data.
- * </p>
- */
-public interface TocReader extends Closeable {
-
- /**
- * Indicates whether or not the corresponding Journal file is compressed
- * @return <code>true</code> if the event file is compressed
- */
- boolean isCompressed();
-
- /**
- * Returns the byte offset into the Journal File for the Block with the given index.
- *
- * @param blockIndex the block index to get the byte offset for
- * @return the byte offset for the given block index, or <code>-1</code> if the given block index
- * does not exist
- */
- long getBlockOffset(int blockIndex);
-
- /**
- * Returns the byte offset into the Journal File of the last Block in the given index
- * @return the byte offset into the Journal File of the last Block in the given index
- */
- long getLastBlockOffset();
-
- /**
- * Returns the index of the block that contains the given offset
- *
- * @param blockOffset the byte offset for which the block index is desired
- *
- * @return the index of the block that contains the given offset
- */
- int getBlockIndex(long blockOffset);
-
- /**
- * Returns the block index where the given event ID should be found
- *
- * @param eventId the ID of the provenance event of interest
- * @return the block index where the given event ID should be found, or <code>null</code> if
- * the block index is not known
- */
- Integer getBlockIndexForEventId(long eventId);
-}
+/*
+ * 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.nifi.provenance.toc;
+
+import java.io.Closeable;
+
+/**
+ * <p>
+ * Reads a Table of Contents (.toc file) for a corresponding Journal File. We use a Table of Contents
+ * to map a Block Index to an offset into the Journal file where that Block begins. We do this so that
+ * we can then persist a Block Index for an event and then compress the Journal later. This way, we can
+ * get good compression by compressing a large batch of events at once, and this way we can also look up
+ * an event in a Journal that has not been compressed by looking in the Table of Contents or lookup the
+ * event in a Journal post-compression by simply rewriting the TOC while we compress the data.
+ * </p>
+ */
+public interface TocReader extends Closeable {
+
+ /**
+ * Indicates whether or not the corresponding Journal file is compressed
+ * @return <code>true</code> if the event file is compressed
+ */
+ boolean isCompressed();
+
+ /**
+ * Returns the byte offset into the Journal File for the Block with the given index.
+ *
+ * @param blockIndex the block index to get the byte offset for
+ * @return the byte offset for the given block index, or <code>-1</code> if the given block index
+ * does not exist
+ */
+ long getBlockOffset(int blockIndex);
+
+ /**
+ * Returns the byte offset into the Journal File of the last Block in the given index
+ * @return the byte offset into the Journal File of the last Block in the given index
+ */
+ long getLastBlockOffset();
+
+ /**
+ * Returns the index of the block that contains the given offset
+ *
+ * @param blockOffset the byte offset for which the block index is desired
+ *
+ * @return the index of the block that contains the given offset
+ */
+ int getBlockIndex(long blockOffset);
+
+ /**
+ * Returns the block index where the given event ID should be found
+ *
+ * @param eventId the ID of the provenance event of interest
+ * @return the block index where the given event ID should be found, or <code>null</code> if
+ * the block index is not known
+ */
+ Integer getBlockIndexForEventId(long eventId);
+}
http://git-wip-us.apache.org/repos/asf/nifi/blob/3a7ddc6a/nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/main/java/org/apache/nifi/provenance/toc/TocUtil.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/main/java/org/apache/nifi/provenance/toc/TocUtil.java b/nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/main/java/org/apache/nifi/provenance/toc/TocUtil.java
index 3fa7d67..28cecd8 100644
--- a/nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/main/java/org/apache/nifi/provenance/toc/TocUtil.java
+++ b/nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/main/java/org/apache/nifi/provenance/toc/TocUtil.java
@@ -1,40 +1,40 @@
-/*
- * 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.nifi.provenance.toc;
-
-import java.io.File;
-
-import org.apache.nifi.provenance.lucene.LuceneUtil;
-
-public class TocUtil {
-
- /**
- * Returns the file that should be used as the Table of Contents for the given Journal File.
- * Note, if no TOC exists for the given Journal File, a File will still be returned but the file
- * will not actually exist.
- *
- * @param journalFile the journal file for which to get the Table of Contents
- * @return the file that represents the Table of Contents for the specified journal file.
- */
- public static File getTocFile(final File journalFile) {
- final File tocDir = new File(journalFile.getParentFile(), "toc");
- final String basename = LuceneUtil.substringBefore(journalFile.getName(), ".");
- final File tocFile = new File(tocDir, basename + ".toc");
- return tocFile;
- }
-
-}
+/*
+ * 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.nifi.provenance.toc;
+
+import java.io.File;
+
+import org.apache.nifi.provenance.lucene.LuceneUtil;
+
+public class TocUtil {
+
+ /**
+ * Returns the file that should be used as the Table of Contents for the given Journal File.
+ * Note, if no TOC exists for the given Journal File, a File will still be returned but the file
+ * will not actually exist.
+ *
+ * @param journalFile the journal file for which to get the Table of Contents
+ * @return the file that represents the Table of Contents for the specified journal file.
+ */
+ public static File getTocFile(final File journalFile) {
+ final File tocDir = new File(journalFile.getParentFile(), "toc");
+ final String basename = LuceneUtil.substringBefore(journalFile.getName(), ".");
+ final File tocFile = new File(tocDir, basename + ".toc");
+ return tocFile;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/nifi/blob/3a7ddc6a/nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/main/java/org/apache/nifi/provenance/toc/TocWriter.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/main/java/org/apache/nifi/provenance/toc/TocWriter.java b/nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/main/java/org/apache/nifi/provenance/toc/TocWriter.java
index 90faea1..fe837c5 100644
--- a/nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/main/java/org/apache/nifi/provenance/toc/TocWriter.java
+++ b/nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/main/java/org/apache/nifi/provenance/toc/TocWriter.java
@@ -1,53 +1,53 @@
-/*
- * 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.nifi.provenance.toc;
-
-import java.io.Closeable;
-import java.io.File;
-import java.io.IOException;
-
-/**
- * Writes a Table-of-Contents (.toc) file
- */
-public interface TocWriter extends Closeable {
-
- /**
- * Adds the given block offset as the next Block Offset in the Table of Contents
- *
- * @param offset the byte offset at which the block begins
- * @param firstEventId the ID of the first Provenance Event that will be in the block
- *
- * @throws IOException if unable to persist the block index
- */
- void addBlockOffset(long offset, long firstEventId) throws IOException;
-
- /**
- * @return the index of the current Block
- */
- int getCurrentBlockIndex();
-
- /**
- * @return the file that is currently being written to
- */
- File getFile();
-
- /**
- * Synchronizes the data with the underlying storage device
- * @throws IOException if unable to synchronize the data with the underlying storage device
- */
- void sync() throws IOException;
-}
+/*
+ * 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.nifi.provenance.toc;
+
+import java.io.Closeable;
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * Writes a Table-of-Contents (.toc) file
+ */
+public interface TocWriter extends Closeable {
+
+ /**
+ * Adds the given block offset as the next Block Offset in the Table of Contents
+ *
+ * @param offset the byte offset at which the block begins
+ * @param firstEventId the ID of the first Provenance Event that will be in the block
+ *
+ * @throws IOException if unable to persist the block index
+ */
+ void addBlockOffset(long offset, long firstEventId) throws IOException;
+
+ /**
+ * @return the index of the current Block
+ */
+ int getCurrentBlockIndex();
+
+ /**
+ * @return the file that is currently being written to
+ */
+ File getFile();
+
+ /**
+ * Synchronizes the data with the underlying storage device
+ * @throws IOException if unable to synchronize the data with the underlying storage device
+ */
+ void sync() throws IOException;
+}
http://git-wip-us.apache.org/repos/asf/nifi/blob/3a7ddc6a/nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/test/java/org/apache/nifi/provenance/TestStandardRecordReaderWriter.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/test/java/org/apache/nifi/provenance/TestStandardRecordReaderWriter.java b/nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/test/java/org/apache/nifi/provenance/TestStandardRecordReaderWriter.java
index d9e64e5..e11502a 100644
--- a/nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/test/java/org/apache/nifi/provenance/TestStandardRecordReaderWriter.java
+++ b/nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/test/java/org/apache/nifi/provenance/TestStandardRecordReaderWriter.java
@@ -1,189 +1,189 @@
-/*
- * 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.nifi.provenance;
-
-import static org.apache.nifi.provenance.TestUtil.createFlowFile;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.UUID;
-
-import org.apache.nifi.provenance.toc.StandardTocReader;
-import org.apache.nifi.provenance.toc.StandardTocWriter;
-import org.apache.nifi.provenance.toc.TocReader;
-import org.apache.nifi.provenance.toc.TocUtil;
-import org.apache.nifi.provenance.toc.TocWriter;
-import org.apache.nifi.util.file.FileUtils;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-public class TestStandardRecordReaderWriter {
- @BeforeClass
- public static void setLogLevel() {
- System.setProperty("org.slf4j.simpleLogger.log.org.apache.nifi.provenance", "DEBUG");
- }
-
- private ProvenanceEventRecord createEvent() {
- final Map<String, String> attributes = new HashMap<>();
- attributes.put("filename", "1.txt");
- attributes.put("uuid", UUID.randomUUID().toString());
-
- final ProvenanceEventBuilder builder = new StandardProvenanceEventRecord.Builder();
- builder.setEventTime(System.currentTimeMillis());
- builder.setEventType(ProvenanceEventType.RECEIVE);
- builder.setTransitUri("nifi://unit-test");
- builder.fromFlowFile(createFlowFile(3L, 3000L, attributes));
- builder.setComponentId("1234");
- builder.setComponentType("dummy processor");
- final ProvenanceEventRecord record = builder.build();
-
- return record;
- }
-
- @Test
- public void testSimpleWriteWithToc() throws IOException {
- final File journalFile = new File("target/storage/" + UUID.randomUUID().toString() + "/testSimpleWrite");
- final File tocFile = TocUtil.getTocFile(journalFile);
- final TocWriter tocWriter = new StandardTocWriter(tocFile, false, false);
- final StandardRecordWriter writer = new StandardRecordWriter(journalFile, tocWriter, false, 1024 * 1024);
-
- writer.writeHeader(1L);
- writer.writeRecord(createEvent(), 1L);
- writer.close();
-
- final TocReader tocReader = new StandardTocReader(tocFile);
-
- try (final FileInputStream fis = new FileInputStream(journalFile);
- final StandardRecordReader reader = new StandardRecordReader(fis, journalFile.getName(), tocReader, 2048)) {
- assertEquals(0, reader.getBlockIndex());
- reader.skipToBlock(0);
- final StandardProvenanceEventRecord recovered = reader.nextRecord();
- assertNotNull(recovered);
-
- assertEquals("nifi://unit-test", recovered.getTransitUri());
- assertNull(reader.nextRecord());
- }
-
- FileUtils.deleteFile(journalFile.getParentFile(), true);
- }
-
-
- @Test
- public void testSingleRecordCompressed() throws IOException {
- final File journalFile = new File("target/storage/" + UUID.randomUUID().toString() + "/testSimpleWrite.gz");
- final File tocFile = TocUtil.getTocFile(journalFile);
- final TocWriter tocWriter = new StandardTocWriter(tocFile, false, false);
- final StandardRecordWriter writer = new StandardRecordWriter(journalFile, tocWriter, true, 100);
-
- writer.writeHeader(1L);
- writer.writeRecord(createEvent(), 1L);
- writer.close();
-
- final TocReader tocReader = new StandardTocReader(tocFile);
-
- try (final FileInputStream fis = new FileInputStream(journalFile);
- final StandardRecordReader reader = new StandardRecordReader(fis, journalFile.getName(), tocReader, 2048)) {
- assertEquals(0, reader.getBlockIndex());
- reader.skipToBlock(0);
- final StandardProvenanceEventRecord recovered = reader.nextRecord();
- assertNotNull(recovered);
-
- assertEquals("nifi://unit-test", recovered.getTransitUri());
- assertNull(reader.nextRecord());
- }
-
- FileUtils.deleteFile(journalFile.getParentFile(), true);
- }
-
-
- @Test
- public void testMultipleRecordsSameBlockCompressed() throws IOException {
- final File journalFile = new File("target/storage/" + UUID.randomUUID().toString() + "/testSimpleWrite.gz");
- final File tocFile = TocUtil.getTocFile(journalFile);
- final TocWriter tocWriter = new StandardTocWriter(tocFile, false, false);
- // new record each 1 MB of uncompressed data
- final StandardRecordWriter writer = new StandardRecordWriter(journalFile, tocWriter, true, 1024 * 1024);
-
- writer.writeHeader(1L);
- for (int i=0; i < 10; i++) {
- writer.writeRecord(createEvent(), i);
- }
- writer.close();
-
- final TocReader tocReader = new StandardTocReader(tocFile);
-
- try (final FileInputStream fis = new FileInputStream(journalFile);
- final StandardRecordReader reader = new StandardRecordReader(fis, journalFile.getName(), tocReader, 2048)) {
- for (int i=0; i < 10; i++) {
- assertEquals(0, reader.getBlockIndex());
-
- // call skipToBlock half the time to ensure that we can; avoid calling it
- // the other half of the time to ensure that it's okay.
- if (i <= 5) {
- reader.skipToBlock(0);
- }
-
- final StandardProvenanceEventRecord recovered = reader.nextRecord();
- assertNotNull(recovered);
- assertEquals("nifi://unit-test", recovered.getTransitUri());
- }
-
- assertNull(reader.nextRecord());
- }
-
- FileUtils.deleteFile(journalFile.getParentFile(), true);
- }
-
-
- @Test
- public void testMultipleRecordsMultipleBlocksCompressed() throws IOException {
- final File journalFile = new File("target/storage/" + UUID.randomUUID().toString() + "/testSimpleWrite.gz");
- final File tocFile = TocUtil.getTocFile(journalFile);
- final TocWriter tocWriter = new StandardTocWriter(tocFile, false, false);
- // new block each 10 bytes
- final StandardRecordWriter writer = new StandardRecordWriter(journalFile, tocWriter, true, 100);
-
- writer.writeHeader(1L);
- for (int i=0; i < 10; i++) {
- writer.writeRecord(createEvent(), i);
- }
- writer.close();
-
- final TocReader tocReader = new StandardTocReader(tocFile);
-
- try (final FileInputStream fis = new FileInputStream(journalFile);
- final StandardRecordReader reader = new StandardRecordReader(fis, journalFile.getName(), tocReader, 2048)) {
- for (int i=0; i < 10; i++) {
- final StandardProvenanceEventRecord recovered = reader.nextRecord();
- System.out.println(recovered);
- assertNotNull(recovered);
- assertEquals(i, recovered.getEventId());
- assertEquals("nifi://unit-test", recovered.getTransitUri());
- }
-
- assertNull(reader.nextRecord());
- }
-
- FileUtils.deleteFile(journalFile.getParentFile(), true);
- }
-}
+/*
+ * 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.nifi.provenance;
+
+import static org.apache.nifi.provenance.TestUtil.createFlowFile;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.nifi.provenance.toc.StandardTocReader;
+import org.apache.nifi.provenance.toc.StandardTocWriter;
+import org.apache.nifi.provenance.toc.TocReader;
+import org.apache.nifi.provenance.toc.TocUtil;
+import org.apache.nifi.provenance.toc.TocWriter;
+import org.apache.nifi.util.file.FileUtils;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class TestStandardRecordReaderWriter {
+ @BeforeClass
+ public static void setLogLevel() {
+ System.setProperty("org.slf4j.simpleLogger.log.org.apache.nifi.provenance", "DEBUG");
+ }
+
+ private ProvenanceEventRecord createEvent() {
+ final Map<String, String> attributes = new HashMap<>();
+ attributes.put("filename", "1.txt");
+ attributes.put("uuid", UUID.randomUUID().toString());
+
+ final ProvenanceEventBuilder builder = new StandardProvenanceEventRecord.Builder();
+ builder.setEventTime(System.currentTimeMillis());
+ builder.setEventType(ProvenanceEventType.RECEIVE);
+ builder.setTransitUri("nifi://unit-test");
+ builder.fromFlowFile(createFlowFile(3L, 3000L, attributes));
+ builder.setComponentId("1234");
+ builder.setComponentType("dummy processor");
+ final ProvenanceEventRecord record = builder.build();
+
+ return record;
+ }
+
+ @Test
+ public void testSimpleWriteWithToc() throws IOException {
+ final File journalFile = new File("target/storage/" + UUID.randomUUID().toString() + "/testSimpleWrite");
+ final File tocFile = TocUtil.getTocFile(journalFile);
+ final TocWriter tocWriter = new StandardTocWriter(tocFile, false, false);
+ final StandardRecordWriter writer = new StandardRecordWriter(journalFile, tocWriter, false, 1024 * 1024);
+
+ writer.writeHeader(1L);
+ writer.writeRecord(createEvent(), 1L);
+ writer.close();
+
+ final TocReader tocReader = new StandardTocReader(tocFile);
+
+ try (final FileInputStream fis = new FileInputStream(journalFile);
+ final StandardRecordReader reader = new StandardRecordReader(fis, journalFile.getName(), tocReader, 2048)) {
+ assertEquals(0, reader.getBlockIndex());
+ reader.skipToBlock(0);
+ final StandardProvenanceEventRecord recovered = reader.nextRecord();
+ assertNotNull(recovered);
+
+ assertEquals("nifi://unit-test", recovered.getTransitUri());
+ assertNull(reader.nextRecord());
+ }
+
+ FileUtils.deleteFile(journalFile.getParentFile(), true);
+ }
+
+
+ @Test
+ public void testSingleRecordCompressed() throws IOException {
+ final File journalFile = new File("target/storage/" + UUID.randomUUID().toString() + "/testSimpleWrite.gz");
+ final File tocFile = TocUtil.getTocFile(journalFile);
+ final TocWriter tocWriter = new StandardTocWriter(tocFile, false, false);
+ final StandardRecordWriter writer = new StandardRecordWriter(journalFile, tocWriter, true, 100);
+
+ writer.writeHeader(1L);
+ writer.writeRecord(createEvent(), 1L);
+ writer.close();
+
+ final TocReader tocReader = new StandardTocReader(tocFile);
+
+ try (final FileInputStream fis = new FileInputStream(journalFile);
+ final StandardRecordReader reader = new StandardRecordReader(fis, journalFile.getName(), tocReader, 2048)) {
+ assertEquals(0, reader.getBlockIndex());
+ reader.skipToBlock(0);
+ final StandardProvenanceEventRecord recovered = reader.nextRecord();
+ assertNotNull(recovered);
+
+ assertEquals("nifi://unit-test", recovered.getTransitUri());
+ assertNull(reader.nextRecord());
+ }
+
+ FileUtils.deleteFile(journalFile.getParentFile(), true);
+ }
+
+
+ @Test
+ public void testMultipleRecordsSameBlockCompressed() throws IOException {
+ final File journalFile = new File("target/storage/" + UUID.randomUUID().toString() + "/testSimpleWrite.gz");
+ final File tocFile = TocUtil.getTocFile(journalFile);
+ final TocWriter tocWriter = new StandardTocWriter(tocFile, false, false);
+ // new record each 1 MB of uncompressed data
+ final StandardRecordWriter writer = new StandardRecordWriter(journalFile, tocWriter, true, 1024 * 1024);
+
+ writer.writeHeader(1L);
+ for (int i=0; i < 10; i++) {
+ writer.writeRecord(createEvent(), i);
+ }
+ writer.close();
+
+ final TocReader tocReader = new StandardTocReader(tocFile);
+
+ try (final FileInputStream fis = new FileInputStream(journalFile);
+ final StandardRecordReader reader = new StandardRecordReader(fis, journalFile.getName(), tocReader, 2048)) {
+ for (int i=0; i < 10; i++) {
+ assertEquals(0, reader.getBlockIndex());
+
+ // call skipToBlock half the time to ensure that we can; avoid calling it
+ // the other half of the time to ensure that it's okay.
+ if (i <= 5) {
+ reader.skipToBlock(0);
+ }
+
+ final StandardProvenanceEventRecord recovered = reader.nextRecord();
+ assertNotNull(recovered);
+ assertEquals("nifi://unit-test", recovered.getTransitUri());
+ }
+
+ assertNull(reader.nextRecord());
+ }
+
+ FileUtils.deleteFile(journalFile.getParentFile(), true);
+ }
+
+
+ @Test
+ public void testMultipleRecordsMultipleBlocksCompressed() throws IOException {
+ final File journalFile = new File("target/storage/" + UUID.randomUUID().toString() + "/testSimpleWrite.gz");
+ final File tocFile = TocUtil.getTocFile(journalFile);
+ final TocWriter tocWriter = new StandardTocWriter(tocFile, false, false);
+ // new block each 10 bytes
+ final StandardRecordWriter writer = new StandardRecordWriter(journalFile, tocWriter, true, 100);
+
+ writer.writeHeader(1L);
+ for (int i=0; i < 10; i++) {
+ writer.writeRecord(createEvent(), i);
+ }
+ writer.close();
+
+ final TocReader tocReader = new StandardTocReader(tocFile);
+
+ try (final FileInputStream fis = new FileInputStream(journalFile);
+ final StandardRecordReader reader = new StandardRecordReader(fis, journalFile.getName(), tocReader, 2048)) {
+ for (int i=0; i < 10; i++) {
+ final StandardProvenanceEventRecord recovered = reader.nextRecord();
+ System.out.println(recovered);
+ assertNotNull(recovered);
+ assertEquals(i, recovered.getEventId());
+ assertEquals("nifi://unit-test", recovered.getTransitUri());
+ }
+
+ assertNull(reader.nextRecord());
+ }
+
+ FileUtils.deleteFile(journalFile.getParentFile(), true);
+ }
+}
http://git-wip-us.apache.org/repos/asf/nifi/blob/3a7ddc6a/nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/test/java/org/apache/nifi/provenance/TestUtil.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/test/java/org/apache/nifi/provenance/TestUtil.java b/nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/test/java/org/apache/nifi/provenance/TestUtil.java
index eb0f736..26766d6 100644
--- a/nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/test/java/org/apache/nifi/provenance/TestUtil.java
+++ b/nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/test/java/org/apache/nifi/provenance/TestUtil.java
@@ -1,82 +1,82 @@
-/*
- * 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.nifi.provenance;
-
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.nifi.flowfile.FlowFile;
-
-public class TestUtil {
- public static FlowFile createFlowFile(final long id, final long fileSize, final Map<String, String> attributes) {
- final Map<String, String> attrCopy = new HashMap<>(attributes);
-
- return new FlowFile() {
- @Override
- public long getId() {
- return id;
- }
-
- @Override
- public long getEntryDate() {
- return System.currentTimeMillis();
- }
-
- @Override
- public Set<String> getLineageIdentifiers() {
- return new HashSet<String>();
- }
-
- @Override
- public long getLineageStartDate() {
- return System.currentTimeMillis();
- }
-
- @Override
- public Long getLastQueueDate() {
- return System.currentTimeMillis();
- }
-
- @Override
- public boolean isPenalized() {
- return false;
- }
-
- @Override
- public String getAttribute(final String s) {
- return attrCopy.get(s);
- }
-
- @Override
- public long getSize() {
- return fileSize;
- }
-
- @Override
- public Map<String, String> getAttributes() {
- return attrCopy;
- }
-
- @Override
- public int compareTo(final FlowFile o) {
- return 0;
- }
- };
- }
-}
+/*
+ * 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.nifi.provenance;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.nifi.flowfile.FlowFile;
+
+public class TestUtil {
+ public static FlowFile createFlowFile(final long id, final long fileSize, final Map<String, String> attributes) {
+ final Map<String, String> attrCopy = new HashMap<>(attributes);
+
+ return new FlowFile() {
+ @Override
+ public long getId() {
+ return id;
+ }
+
+ @Override
+ public long getEntryDate() {
+ return System.currentTimeMillis();
+ }
+
+ @Override
+ public Set<String> getLineageIdentifiers() {
+ return new HashSet<String>();
+ }
+
+ @Override
+ public long getLineageStartDate() {
+ return System.currentTimeMillis();
+ }
+
+ @Override
+ public Long getLastQueueDate() {
+ return System.currentTimeMillis();
+ }
+
+ @Override
+ public boolean isPenalized() {
+ return false;
+ }
+
+ @Override
+ public String getAttribute(final String s) {
+ return attrCopy.get(s);
+ }
+
+ @Override
+ public long getSize() {
+ return fileSize;
+ }
+
+ @Override
+ public Map<String, String> getAttributes() {
+ return attrCopy;
+ }
+
+ @Override
+ public int compareTo(final FlowFile o) {
+ return 0;
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/nifi/blob/3a7ddc6a/nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/test/java/org/apache/nifi/provenance/toc/TestStandardTocReader.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/test/java/org/apache/nifi/provenance/toc/TestStandardTocReader.java b/nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/test/java/org/apache/nifi/provenance/toc/TestStandardTocReader.java
index 9a5f424..dc9a018 100644
--- a/nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/test/java/org/apache/nifi/provenance/toc/TestStandardTocReader.java
+++ b/nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/test/java/org/apache/nifi/provenance/toc/TestStandardTocReader.java
@@ -1,118 +1,118 @@
-/*
- * 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.nifi.provenance.toc;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import java.io.DataOutputStream;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.util.UUID;
-
-import org.junit.Test;
-
-public class TestStandardTocReader {
-
- @Test
- public void testDetectsCompression() throws IOException {
- final File file = new File("target/" + UUID.randomUUID().toString());
- try (final OutputStream out = new FileOutputStream(file)) {
- out.write(0);
- out.write(0);
- }
-
- try {
- try(final StandardTocReader reader = new StandardTocReader(file)) {
- assertFalse(reader.isCompressed());
- }
- } finally {
- file.delete();
- }
-
-
- try (final OutputStream out = new FileOutputStream(file)) {
- out.write(0);
- out.write(1);
- }
-
- try {
- try(final StandardTocReader reader = new StandardTocReader(file)) {
- assertTrue(reader.isCompressed());
- }
- } finally {
- file.delete();
- }
- }
-
-
- @Test
- public void testGetBlockIndexV1() throws IOException {
- final File file = new File("target/" + UUID.randomUUID().toString());
- try (final OutputStream out = new FileOutputStream(file);
- final DataOutputStream dos = new DataOutputStream(out)) {
- out.write(1);
- out.write(0);
-
- for (int i=0; i < 1024; i++) {
- dos.writeLong(i * 1024L);
- }
- }
-
- try {
- try(final StandardTocReader reader = new StandardTocReader(file)) {
- assertFalse(reader.isCompressed());
-
- for (int i=0; i < 1024; i++) {
- assertEquals(i * 1024, reader.getBlockOffset(i));
- }
- }
- } finally {
- file.delete();
- }
- }
-
- @Test
- public void testGetBlockIndexV2() throws IOException {
- final File file = new File("target/" + UUID.randomUUID().toString());
- try (final OutputStream out = new FileOutputStream(file);
- final DataOutputStream dos = new DataOutputStream(out)) {
- out.write(2);
- out.write(0);
-
- for (int i=0; i < 1024; i++) {
- dos.writeLong(i * 1024L);
- dos.writeLong(0L);
- }
- }
-
- try {
- try(final StandardTocReader reader = new StandardTocReader(file)) {
- assertFalse(reader.isCompressed());
-
- for (int i=0; i < 1024; i++) {
- assertEquals(i * 1024, reader.getBlockOffset(i));
- }
- }
- } finally {
- file.delete();
- }
- }
-}
+/*
+ * 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.nifi.provenance.toc;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.io.DataOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.UUID;
+
+import org.junit.Test;
+
+public class TestStandardTocReader {
+
+ @Test
+ public void testDetectsCompression() throws IOException {
+ final File file = new File("target/" + UUID.randomUUID().toString());
+ try (final OutputStream out = new FileOutputStream(file)) {
+ out.write(0);
+ out.write(0);
+ }
+
+ try {
+ try(final StandardTocReader reader = new StandardTocReader(file)) {
+ assertFalse(reader.isCompressed());
+ }
+ } finally {
+ file.delete();
+ }
+
+
+ try (final OutputStream out = new FileOutputStream(file)) {
+ out.write(0);
+ out.write(1);
+ }
+
+ try {
+ try(final StandardTocReader reader = new StandardTocReader(file)) {
+ assertTrue(reader.isCompressed());
+ }
+ } finally {
+ file.delete();
+ }
+ }
+
+
+ @Test
+ public void testGetBlockIndexV1() throws IOException {
+ final File file = new File("target/" + UUID.randomUUID().toString());
+ try (final OutputStream out = new FileOutputStream(file);
+ final DataOutputStream dos = new DataOutputStream(out)) {
+ out.write(1);
+ out.write(0);
+
+ for (int i=0; i < 1024; i++) {
+ dos.writeLong(i * 1024L);
+ }
+ }
+
+ try {
+ try(final StandardTocReader reader = new StandardTocReader(file)) {
+ assertFalse(reader.isCompressed());
+
+ for (int i=0; i < 1024; i++) {
+ assertEquals(i * 1024, reader.getBlockOffset(i));
+ }
+ }
+ } finally {
+ file.delete();
+ }
+ }
+
+ @Test
+ public void testGetBlockIndexV2() throws IOException {
+ final File file = new File("target/" + UUID.randomUUID().toString());
+ try (final OutputStream out = new FileOutputStream(file);
+ final DataOutputStream dos = new DataOutputStream(out)) {
+ out.write(2);
+ out.write(0);
+
+ for (int i=0; i < 1024; i++) {
+ dos.writeLong(i * 1024L);
+ dos.writeLong(0L);
+ }
+ }
+
+ try {
+ try(final StandardTocReader reader = new StandardTocReader(file)) {
+ assertFalse(reader.isCompressed());
+
+ for (int i=0; i < 1024; i++) {
+ assertEquals(i * 1024, reader.getBlockOffset(i));
+ }
+ }
+ } finally {
+ file.delete();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/nifi/blob/3a7ddc6a/nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/test/java/org/apache/nifi/provenance/toc/TestStandardTocWriter.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/test/java/org/apache/nifi/provenance/toc/TestStandardTocWriter.java b/nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/test/java/org/apache/nifi/provenance/toc/TestStandardTocWriter.java
index aebe0d5..ff9ebbf 100644
--- a/nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/test/java/org/apache/nifi/provenance/toc/TestStandardTocWriter.java
+++ b/nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/test/java/org/apache/nifi/provenance/toc/TestStandardTocWriter.java
@@ -1,42 +1,42 @@
-/*
- * 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.nifi.provenance.toc;
-
-import static org.junit.Assert.assertTrue;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.UUID;
-
-import org.apache.nifi.util.file.FileUtils;
-import org.junit.Test;
-
-public class TestStandardTocWriter {
- @Test
- public void testOverwriteEmptyFile() throws IOException {
- final File tocFile = new File("target/" + UUID.randomUUID().toString() + ".toc");
- try {
- assertTrue( tocFile.createNewFile() );
-
- try (final StandardTocWriter writer = new StandardTocWriter(tocFile, false, false)) {
- }
- } finally {
- FileUtils.deleteFile(tocFile, false);
- }
- }
-
-}
+/*
+ * 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.nifi.provenance.toc;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.UUID;
+
+import org.apache.nifi.util.file.FileUtils;
+import org.junit.Test;
+
+public class TestStandardTocWriter {
+ @Test
+ public void testOverwriteEmptyFile() throws IOException {
+ final File tocFile = new File("target/" + UUID.randomUUID().toString() + ".toc");
+ try {
+ assertTrue( tocFile.createNewFile() );
+
+ try (final StandardTocWriter writer = new StandardTocWriter(tocFile, false, false)) {
+ }
+ } finally {
+ FileUtils.deleteFile(tocFile, false);
+ }
+ }
+
+}