Mercurial > stress-tester
changeset 666:003105670d98
NC file in progress
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/reader/DataBlock.java Fri Nov 17 12:32:14 2017 +0100 +++ b/stress-tester/src/main/java/com/passus/st/reader/DataBlock.java Fri Nov 17 12:49:13 2017 +0100 @@ -6,8 +6,6 @@ */ public interface DataBlock { - public long getTimestamp(); - - public byte[] getData(); + public int getType(); }
--- a/stress-tester/src/main/java/com/passus/st/reader/DataBlockReader.java Fri Nov 17 12:32:14 2017 +0100 +++ b/stress-tester/src/main/java/com/passus/st/reader/DataBlockReader.java Fri Nov 17 12:49:13 2017 +0100 @@ -1,6 +1,5 @@ package com.passus.st.reader; -import com.passus.st.reader.pcap.PcapDataBlock; import java.io.Closeable; import java.io.IOException; @@ -8,12 +7,12 @@ * * @author Mirosław Hawrot */ -public interface DataBlockReader extends Closeable { +public interface DataBlockReader<T> extends Closeable { public void open() throws IOException; public void reset() throws IOException; - public PcapDataBlock read() throws IOException; + public T read() throws IOException; }
--- a/stress-tester/src/main/java/com/passus/st/reader/DataBlockWriter.java Fri Nov 17 12:32:14 2017 +0100 +++ b/stress-tester/src/main/java/com/passus/st/reader/DataBlockWriter.java Fri Nov 17 12:49:13 2017 +0100 @@ -7,10 +7,10 @@ * * @author Mirosław Hawrot */ -public interface DataBlockWriter extends Closeable { +public interface DataBlockWriter<T> extends Closeable { public void open() throws IOException; - public void write(DataBlock block) throws IOException; + public void write(T block) throws IOException; }
--- a/stress-tester/src/main/java/com/passus/st/reader/nc/NcDataBlockReader.java Fri Nov 17 12:32:14 2017 +0100 +++ b/stress-tester/src/main/java/com/passus/st/reader/nc/NcDataBlockReader.java Fri Nov 17 12:49:13 2017 +0100 @@ -1,14 +1,9 @@ package com.passus.st.reader.nc; import com.passus.commons.Assert; -import com.passus.data.ByteBuff; import com.passus.data.DataHelper; -import com.passus.data.DataProcessor; -import com.passus.data.DataUtils; -import com.passus.data.compression.DeflaterProcessor; -import com.passus.data.compression.GZIPDecompressionProcessor; import com.passus.st.reader.DataBlockReader; -import com.passus.st.reader.pcap.PcapDataBlock; +import com.passus.st.reader.nc.block.NcDataBlock; import java.io.File; import java.io.IOException; import java.nio.ByteBuffer; @@ -22,30 +17,28 @@ * * @author Mirosław Hawrot */ -public class NcDataBlockReader implements DataBlockReader { +public class NcDataBlockReader implements DataBlockReader<NcDataBlock> { public static final byte VERSION_MAJOR = 1; public static final byte VERSION_MINOR = 0; - public static final int COMPRESSION_NONE = 0; - public static final int COMPRESSION_GZIP = 1; - public static final int COMPRESSION_DEFLATE = 2; - private static final int DEFAULT_BUFFER_SIZE = 64 * 1024; private NcHeader header; private DataHelper helper = DataHelper.BIG_ENDIAN; - private DataProcessor decompressProc; - private final Path path; private FileChannel ch; private int bufferSize = DEFAULT_BUFFER_SIZE; - private ByteBuffer byteBuffer; + private ByteBuffer buffer; + + private ByteBuffer[] buffers; + + private boolean opened = false; public NcDataBlockReader(String fileName) { this.path = Paths.get(fileName); @@ -60,13 +53,8 @@ this.path = path; } - public int getBufferSize() { - return bufferSize; - } - - public void setBufferSize(int bufferSize) { - Assert.greaterThanZero(bufferSize, "bufferSize"); - this.bufferSize = bufferSize; + public NcHeader getHeader() { + return header; } @Override @@ -77,51 +65,74 @@ throw new IOException("File '" + path + "' is not readable."); } - ch = FileChannel.open(path, StandardOpenOption.READ); - byteBuffer = ByteBuffer.allocate(bufferSize); + try { + ch = FileChannel.open(path, StandardOpenOption.READ); + buffer = ByteBuffer.allocate(bufferSize); + buffers = new ByteBuffer[1]; + buffers[0] = buffer; + opened = true; + + readHeader(); + } catch (IOException e) { + close(); + throw e; + } + } @Override public void close() throws IOException { if (ch != null) { - ch.close(); - ch = null; - byteBuffer = null; + try { + ch.close(); + } catch (Exception ignore) { + } } + + ch = null; + buffer = null; + buffers = null; + opened = false; } @Override public void reset() throws IOException { header = null; - decompressProc = null; + } - private void readHeader(ByteBuff buffer) throws IOException { - if (!NcHeader.isPreambule(buffer.buffer(), 0)) { + private void readBytes(int offset, int length) throws IOException { + buffer.clear(); + long readed = ch.read(buffers, offset, length); + } + + private void readHeader() throws IOException { + readBytes(0, bufferSize); + + byte[] data = buffer.array(); + int offset = buffer.arrayOffset(); + + if (!NcHeader.isPreambule(data, offset)) { throw new IOException("Invalid preambule."); } - buffer.skipBytes(NcHeader.PREAMBULE.length); + offset += NcHeader.PREAMBULE.length; - byte verMajor = DataUtils.readByte(buffer); - byte varMinor = DataUtils.readByte(buffer); + byte verMajor = data[offset++]; + byte varMinor = data[offset++]; if (varMinor != VERSION_MAJOR || varMinor != VERSION_MINOR) { throw new IOException("Not supported version."); } - byte compressionMethod = DataUtils.readByte(buffer); - if (compressionMethod == COMPRESSION_GZIP) { - decompressProc = new GZIPDecompressionProcessor(); - } else if (compressionMethod == COMPRESSION_DEFLATE) { - decompressProc = new DeflaterProcessor(); - } else if (compressionMethod != COMPRESSION_NONE) { - throw new IOException("Not supported compression method code '" + compressionMethod + "'."); - } - - header = new NcHeader(verMajor, varMinor, compressionMethod); + header = new NcHeader(verMajor, varMinor); + buffer.position(NcHeader.PREAMBULE.length - 1); } @Override - public PcapDataBlock read() throws IOException { + public NcDataBlock read() throws IOException { + if (!opened) { + throw new IOException("Reader is not opened."); + } + throw new UnsupportedOperationException("Not supported yet."); }
--- a/stress-tester/src/main/java/com/passus/st/reader/nc/NcDataBlockWriter.java Fri Nov 17 12:32:14 2017 +0100 +++ b/stress-tester/src/main/java/com/passus/st/reader/nc/NcDataBlockWriter.java Fri Nov 17 12:49:13 2017 +0100 @@ -1,28 +1,194 @@ package com.passus.st.reader.nc; -import com.passus.st.reader.DataBlock; +import com.passus.commons.Assert; +import com.passus.st.emitter.SessionInfo; import com.passus.st.reader.DataBlockWriter; +import com.passus.st.reader.nc.block.NcDataBlock; +import java.io.File; import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.channels.FileChannel; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardOpenOption; +import java.util.HashMap; +import java.util.Map; +import static com.passus.st.reader.nc.NcDataUtilsTmp.writeStringNullTerminated; +import static com.passus.st.reader.nc.NcDataUtilsTmp.writeIpAddress; /** * * @author Mirosław Hawrot */ -public class NcDataBlockWriter implements DataBlockWriter { +public class NcDataBlockWriter implements DataBlockWriter<NcDataBlock> { + + private static final int DEFAULT_MAX_SEGMENT_BLOCKS = 256; + + private static final int DEFAULT_BYTE_BUFFER = 64 * 1024; + + private final Path path; + + private FileChannel ch; + + private boolean opened; + + private int bufferSize = DEFAULT_BYTE_BUFFER; + + private int maxSegmentBlocks = DEFAULT_MAX_SEGMENT_BLOCKS; + + private int currentSegmentsBlocks = -1; + + private long currentSegmentSize = -1; + + private final Map<SessionInfo, Integer> sessionIdMap = new HashMap<>(); + + private ByteBuffer buffer = ByteBuffer.allocate(bufferSize); + + public NcDataBlockWriter(String fileName) { + this.path = Paths.get(fileName); + } + + public NcDataBlockWriter(File file) { + this.path = file.toPath(); + } + + public NcDataBlockWriter(Path path) { + Assert.notNull(path, "path"); + this.path = path; + } + + public int getMaxSegmentBlocks() { + return maxSegmentBlocks; + } + + public void setMaxSegmentBlocks(int maxSegmentBlocks) { + Assert.greaterThanZero(maxSegmentBlocks, "maxSegmentBlocks"); + this.maxSegmentBlocks = maxSegmentBlocks; + } + + private void writeBuffer() throws IOException { + buffer.flip(); + ch.write(buffer); + buffer.clear(); + } + + public void flush() throws IOException { + ch.force(true); + } @Override public void open() throws IOException { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public void write(DataBlock block) throws IOException { - throw new UnsupportedOperationException("Not supported yet."); + try { + ch = FileChannel.open(path, StandardOpenOption.WRITE, StandardOpenOption.CREATE_NEW); + writeHeader(); + opened = true; + } catch (IOException e) { + close(); + throw e; + } } @Override public void close() throws IOException { - throw new UnsupportedOperationException("Not supported yet."); + if (ch != null) { + try { + flush(); + ch.close(); + } catch (Exception ignore) { + } + } + + opened = false; } - + + private void checkOpened() { + if (!opened) { + throw new IllegalStateException("Writer is not opened."); + } + } + + private int writeHeader() throws IOException { + buffer.clear(); + buffer.put(NcHeader.PREAMBULE); + buffer.put(NcDataUtils.VERSION_MAJOR); + buffer.put(NcDataUtils.VERSION_MINOR); + buffer.putLong(0L); + writeBuffer(); + return NcHeader.SIZE; + } + + private int getSessionId(SessionInfo session, boolean writeIfNeeded) { + Integer sessionId = sessionIdMap.get(session); + if (writeIfNeeded && sessionId == null) { + sessionId = writeSessionInfoBlock(session); + } + + return sessionId; + } + + private void resetSegmentInfo() { + currentSegmentsBlocks = -1; + currentSegmentSize = -1; + sessionIdMap.clear(); + } + + private void writeSegmentBlock(long position) throws IOException { + currentSegmentsBlocks = 0; + currentSegmentSize = 0; + } + + private int writeSessionInfoBlock(SessionInfo sessionInfo) { + int size = sessionIdMap.size(); + int sessionId = size + 1; + + if (sessionIdMap.put(sessionInfo, sessionId) != null) { + throw new IllegalStateException("Session block '" + sessionInfo + "' already exists."); + } + + buffer.putInt(sessionId); + writeStringNullTerminated(buffer, sessionInfo.getSourceName()); + buffer.put((byte) sessionInfo.getTransport()); + writeIpAddress(buffer, sessionInfo.getSrcIp()); + buffer.putShort((short) sessionInfo.getSrcPort()); + writeIpAddress(buffer, sessionInfo.getDstIp()); + buffer.putShort((short) sessionInfo.getDstPort()); + return sessionId; + } + + public void writeSessionStatusBlock(long timestamp, SessionInfo session, byte status) { + checkOpened(); + + int sessionId = getSessionId(session, true); + + buffer.putLong(timestamp); + buffer.putInt(sessionId); + buffer.put(status); + } + + public void writeSessionPayload(long timestamp, SessionInfo session, byte proto, byte[] data) throws IOException { + checkOpened(); + + writeSessionPayload(timestamp, session, proto, data, (byte) 0); + } + + public void writeSessionPayload(long timestamp, SessionInfo session, byte proto, byte[] data, byte flags) throws IOException { + checkOpened(); + + int sessionId = sessionIdMap.get(session); + + buffer.clear(); + buffer.putLong(timestamp); + buffer.putInt(sessionId); + buffer.put(flags); + buffer.put(proto); + buffer.putInt(data.length); //@TODO Length - zmien na format docelowy + + ch.write(new ByteBuffer[]{buffer, ByteBuffer.wrap(data)}); + } + + @Override + public void write(NcDataBlock block) throws IOException { + checkOpened(); + } + }
--- a/stress-tester/src/main/java/com/passus/st/reader/nc/NcDataUtils.java Fri Nov 17 12:32:14 2017 +0100 +++ b/stress-tester/src/main/java/com/passus/st/reader/nc/NcDataUtils.java Fri Nov 17 12:49:13 2017 +0100 @@ -12,6 +12,10 @@ */ public class NcDataUtils { + public static final byte VERSION_MAJOR = 1; + + public static final byte VERSION_MINOR = 0; + public static final int LONG_LENGTH = 0x80; public static final int SHORT_LENGTH_MAX = 0x7F;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/stress-tester/src/main/java/com/passus/st/reader/nc/NcDataUtilsTmp.java Fri Nov 17 12:49:13 2017 +0100 @@ -0,0 +1,32 @@ +package com.passus.st.reader.nc; + +import com.passus.commons.AsciiUtils; +import com.passus.net.IpAddress; +import java.nio.ByteBuffer; +import java.nio.charset.Charset; + +/** + * + * @author Mirosław Hawrot + * + */ +/* @TODO Klasa tymczasowa - do usuniecia. Metody przeniesc do NcDataUtils. */ +public class NcDataUtilsTmp { + + public static final Charset CHARSET = Charset.forName("UTF-8"); + + public static int writeStringNullTerminated(ByteBuffer buffer, String value) { + byte[] data = value.getBytes(CHARSET); + buffer.put(data); + buffer.put(AsciiUtils.NUL); + return data.length + 1; + } + + public static int writeIpAddress(ByteBuffer buffer, IpAddress ip) { + byte[] data = ip.getAddress(); + buffer.put((byte) ip.getVersion()); + buffer.put(data); + return data.length + 1; + } + +}
--- a/stress-tester/src/main/java/com/passus/st/reader/nc/NcHeader.java Fri Nov 17 12:32:14 2017 +0100 +++ b/stress-tester/src/main/java/com/passus/st/reader/nc/NcHeader.java Fri Nov 17 12:49:13 2017 +0100 @@ -6,6 +6,8 @@ */ public class NcHeader { + public static final int SIZE = 18; + public static final byte[] PREAMBULE = { (byte) 'S', (byte) 'T', (byte) 'N', (byte) 'e', (byte) 't', @@ -16,12 +18,9 @@ private final int versionMinor; - private final int compressionMethod; - - public NcHeader(int versionMajor, int versionMinor, int compressionMethod) { + public NcHeader(int versionMajor, int versionMinor) { this.versionMajor = versionMajor; this.versionMinor = versionMinor; - this.compressionMethod = compressionMethod; } public int getVersionMajor() { @@ -32,10 +31,6 @@ return versionMinor; } - public int getCompressionMethod() { - return compressionMethod; - } - public static boolean isPreambule(byte[] data, int offset) { if (data.length - offset < PREAMBULE.length) { return false;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/stress-tester/src/main/java/com/passus/st/reader/nc/block/NcDataBlock.java Fri Nov 17 12:49:13 2017 +0100 @@ -0,0 +1,11 @@ +package com.passus.st.reader.nc.block; + +/** + * + * @author Mirosław Hawrot + */ +public interface NcDataBlock { + + public int getType(); + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/stress-tester/src/main/java/com/passus/st/reader/nc/block/NcSegmentBlock.java Fri Nov 17 12:49:13 2017 +0100 @@ -0,0 +1,18 @@ +package com.passus.st.reader.nc.block; + +/** + * + * @author Mirosław Hawrot + */ +public class NcSegmentBlock implements NcDataBlock { + + public static final int TYPE = 1; + + private long totalSize; + + @Override + public int getType() { + return TYPE; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/stress-tester/src/main/java/com/passus/st/reader/nc/block/NcSessionBlock.java Fri Nov 17 12:49:13 2017 +0100 @@ -0,0 +1,29 @@ +package com.passus.st.reader.nc.block; + +/** + * + * @author Mirosław Hawrot + */ +public abstract class NcSessionBlock { + + private long timestamp; + + private int sessionId; + + public long timestamp() { + return timestamp; + } + + public void timestamp(long timestamp) { + this.timestamp = timestamp; + } + + public int sessionId() { + return sessionId; + } + + public void sessionId(int sessionId) { + this.sessionId = sessionId; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/stress-tester/src/main/java/com/passus/st/reader/nc/block/NcSessionInfoBlock.java Fri Nov 17 12:49:13 2017 +0100 @@ -0,0 +1,71 @@ +package com.passus.st.reader.nc.block; + +import com.passus.net.IpAddress; + +/** + * + * @author Mirosław Hawrot + */ +public class NcSessionInfoBlock { + + private int sessionId; + + private byte transport; + + private IpAddress clientAddress; + + private int clientPort; + + private IpAddress serverAddress; + + private int serverPort; + + public int sessionId() { + return sessionId; + } + + public void sessionId(int sessionId) { + this.sessionId = sessionId; + } + + public byte transport() { + return transport; + } + + public void transport(byte transport) { + this.transport = transport; + } + + public IpAddress clientAddress() { + return clientAddress; + } + + public void clientAddress(IpAddress clientAddress) { + this.clientAddress = clientAddress; + } + + public int clientPort() { + return clientPort; + } + + public void clientPort(int clientPort) { + this.clientPort = clientPort; + } + + public IpAddress serverAddress() { + return serverAddress; + } + + public void serverAddress(IpAddress serverAddress) { + this.serverAddress = serverAddress; + } + + public int serverPort() { + return serverPort; + } + + public void serverPort(int serverPort) { + this.serverPort = serverPort; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/stress-tester/src/main/java/com/passus/st/reader/nc/block/NcSessionPayloadBlock.java Fri Nov 17 12:49:13 2017 +0100 @@ -0,0 +1,61 @@ +package com.passus.st.reader.nc.block; + +/** + * + * @author Mirosław Hawrot + */ +public class NcSessionPayloadBlock extends NcSessionBlock { + + public static final byte FLAG_ENCODED = 1; + + private byte flags; + + private int proto; + + private long dataLength; + + private Object data; + + private int optionsLength = 0; + + public byte flags() { + return flags; + } + + public void flags(byte flags) { + this.flags = flags; + } + + public int proto() { + return proto; + } + + public void proto(int proto) { + this.proto = proto; + } + + public long dataLength() { + return dataLength; + } + + public void dataLength(long dataLength) { + this.dataLength = dataLength; + } + + public Object data() { + return data; + } + + public void data(Object data) { + this.data = data; + } + + public int optionsLength() { + return optionsLength; + } + + public void optionsLength(int optionsLength) { + this.optionsLength = optionsLength; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/stress-tester/src/main/java/com/passus/st/reader/nc/block/NcSessionStatusBlock.java Fri Nov 17 12:49:13 2017 +0100 @@ -0,0 +1,19 @@ +package com.passus.st.reader.nc.block; + +/** + * + * @author Mirosław Hawrot + */ +public class NcSessionStatusBlock extends NcSessionBlock { + + private byte status; + + public byte status() { + return status; + } + + public void status(byte status) { + this.status = status; + } + +}
--- a/stress-tester/src/main/java/com/passus/st/reader/nc/block/SegmentBlock.java Fri Nov 17 12:32:14 2017 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,11 +0,0 @@ -package com.passus.st.reader.nc.block; - -/** - * - * @author Mirosław Hawrot - */ -public class SegmentBlock { - - private long totalSize; - -}
--- a/stress-tester/src/main/java/com/passus/st/reader/pcap/PcapDataBlock.java Fri Nov 17 12:32:14 2017 +0100 +++ b/stress-tester/src/main/java/com/passus/st/reader/pcap/PcapDataBlock.java Fri Nov 17 12:49:13 2017 +0100 @@ -1,6 +1,5 @@ package com.passus.st.reader.pcap; -import com.passus.st.reader.DataBlock; import com.passus.data.DataHelper; import java.nio.ByteBuffer; import java.nio.ByteOrder; @@ -9,7 +8,7 @@ * * @author mikolaj.podbielski */ -public class PcapDataBlock implements DataBlock { +public class PcapDataBlock { private long timestampUs; private int tsSec; @@ -23,8 +22,8 @@ public PcapDataBlock(long timestampUs, int length, int originalLength) { this.timestampUs = timestampUs; - this.tsSec = (int) (timestampUs / 1000_000); - this.tsUsec = (int) (timestampUs % 1000_000); + this.tsSec = (int) (timestampUs / 1_000_000); + this.tsUsec = (int) (timestampUs % 1_000_000); this.length = length; this.originalLength = originalLength; } @@ -53,7 +52,6 @@ return header; } - @Override public long getTimestamp() { return timestampUs / 1000; } @@ -78,7 +76,6 @@ return originalLength; } - @Override public byte[] getData() { return data; }
--- a/stress-tester/src/main/java/com/passus/st/reader/pcap/PcapDataBlockReader.java Fri Nov 17 12:32:14 2017 +0100 +++ b/stress-tester/src/main/java/com/passus/st/reader/pcap/PcapDataBlockReader.java Fri Nov 17 12:49:13 2017 +0100 @@ -13,7 +13,7 @@ * * @author mikolaj.podbielski */ -public final class PcapDataBlockReader implements DataBlockReader { +public final class PcapDataBlockReader implements DataBlockReader<PcapDataBlock> { private final File pcapFile; private FileInputStream fis = null;
--- a/stress-tester/src/main/java/com/passus/st/source/PcapSessionEventSource.java Fri Nov 17 12:32:14 2017 +0100 +++ b/stress-tester/src/main/java/com/passus/st/source/PcapSessionEventSource.java Fri Nov 17 12:49:13 2017 +0100 @@ -35,7 +35,6 @@ import com.passus.st.metric.MetricSource; import com.passus.st.metric.MetricsContainer; import com.passus.st.plugin.PluginConstants; -import com.passus.st.reader.DataBlock; import com.passus.st.reader.pcap.PcapDataBlock; import com.passus.st.reader.pcap.PcapDataBlockReader; import java.io.IOException; @@ -387,7 +386,7 @@ loopCorrection = relativeTimestamp + loopDelay; } - public void handle(DataBlock dataBlock) { + public void handle(PcapDataBlock dataBlock) { Frame frame = new MemoryFrame(dataBlock.getData(), dataBlock.getTimestamp()); frameDecoder.decode(frame); frame.setNumber(frameNum++);
--- a/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpFiltersNodeDefinitionCreatorTest.java Fri Nov 17 12:32:14 2017 +0100 +++ b/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpFiltersNodeDefinitionCreatorTest.java Fri Nov 17 12:49:13 2017 +0100 @@ -8,7 +8,6 @@ import com.passus.config.Configuration; import com.passus.config.ConfigurationContext; import com.passus.config.YamlConfigurationReader; -import com.passus.config.schema.KeyValueVaryListNodeDefinition; import com.passus.config.schema.NodeDefinition; import com.passus.config.validation.Errors; import com.passus.st.client.http.filter.HttpMessageModificationFilter.*;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/stress-tester/src/test/java/com/passus/st/reader/nc/NcDataBlockWriterTest.java Fri Nov 17 12:49:13 2017 +0100 @@ -0,0 +1,42 @@ +package com.passus.st.reader.nc; + +import java.io.File; +import java.io.IOException; +import java.util.UUID; +import org.apache.commons.io.FileUtils; +import static org.testng.AssertJUnit.assertTrue; +import org.testng.annotations.Test; + +/** + * + * @author Mirosław Hawrot + */ +public class NcDataBlockWriterTest { + + private File createTmpFile() throws IOException { + File tmpDir = new File(System.getProperty("java.io.tmpdir"), "st"); + if (!tmpDir.exists()) { + tmpDir.mkdir(); + } + + return new File(tmpDir, "st_" + UUID.randomUUID().toString() + ".tmp"); + } + + @Test + public void testWrite_Header() throws Exception { + File tmpFile = createTmpFile(); + + try { + try (NcDataBlockWriter writer = new NcDataBlockWriter(tmpFile)) { + writer.open(); + } + + byte[] content = FileUtils.readFileToByteArray(tmpFile); + assertTrue(NcHeader.isPreambule(content, 0)); + } finally { + tmpFile.delete(); + } + + } + +}