From 17fe2f1b66f69aa91eef5eb7a8132ca8f929584f Mon Sep 17 00:00:00 2001 From: Mikhail Zelenyy Date: Wed, 6 Nov 2019 16:08:21 +0300 Subject: [PATCH 1/6] Split test for Tagged and Tagless format. Tagless test failed. --- .../hep/dataforge/io/FileEnvelopeTest.kt | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/dataforge-io/src/jvmTest/kotlin/hep/dataforge/io/FileEnvelopeTest.kt b/dataforge-io/src/jvmTest/kotlin/hep/dataforge/io/FileEnvelopeTest.kt index ba7f7cc5..46643ef2 100644 --- a/dataforge-io/src/jvmTest/kotlin/hep/dataforge/io/FileEnvelopeTest.kt +++ b/dataforge-io/src/jvmTest/kotlin/hep/dataforge/io/FileEnvelopeTest.kt @@ -28,4 +28,37 @@ class FileEnvelopeTest { val restored: Envelope = Global.io.readEnvelopeFile(tmpPath) assertTrue { envelope.contentEquals(restored) } } + + @Test + fun testFileWriteTagged() { + val tmpPath = Files.createTempFile("dataforge_test", ".df") + Global.io.writeEnvelopeFile(tmpPath, envelope) + assertTrue { tmpPath.toFile().length() > 0 } + } + + @Test + fun testFileWriteReadTagged() { + val tmpPath = Files.createTempFile("dataforge_test", ".df") + Global.io.writeEnvelopeFile(tmpPath, envelope) + println(tmpPath.toUri()) + val restored: Envelope = Global.io.readEnvelopeFile(tmpPath) + assertTrue { envelope.contentEquals(restored) } + } + + @Test + fun testFileWriteTagless() { + val tmpPath = Files.createTempFile("dataforge_test", ".df") + Global.io.writeEnvelopeFile(tmpPath, envelope, formatFactory = TaglessEnvelopeFormat) + assertTrue { tmpPath.toFile().length() > 0 } + } + + @Test + fun testFileWriteReadTagless() { + val tmpPath = Files.createTempFile("dataforge_test", ".df") + Global.io.writeEnvelopeFile(tmpPath, envelope, formatFactory = TaglessEnvelopeFormat) + println(tmpPath.toUri()) + val restored: Envelope = Global.io.readEnvelopeFile(tmpPath, formatFactory = TaglessEnvelopeFormat) + assertTrue { envelope.contentEquals(restored) } + } + } \ No newline at end of file -- 2.34.1 From 9f1cf2fcc3d881b8f25f915b86b83db1801e0c2d Mon Sep 17 00:00:00 2001 From: Mikhail Zelenyy Date: Wed, 6 Nov 2019 16:09:29 +0300 Subject: [PATCH 2/6] Fix flush in Tagless format --- .../commonMain/kotlin/hep/dataforge/io/TaglessEnvelopeFormat.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/dataforge-io/src/commonMain/kotlin/hep/dataforge/io/TaglessEnvelopeFormat.kt b/dataforge-io/src/commonMain/kotlin/hep/dataforge/io/TaglessEnvelopeFormat.kt index 14d871db..c9d32c9f 100644 --- a/dataforge-io/src/commonMain/kotlin/hep/dataforge/io/TaglessEnvelopeFormat.kt +++ b/dataforge-io/src/commonMain/kotlin/hep/dataforge/io/TaglessEnvelopeFormat.kt @@ -43,6 +43,7 @@ class TaglessEnvelopeFormat( writeText(dataStart + "\r\n") writeFully(data.toBytes()) } + flush() } override fun Input.readObject(): Envelope { -- 2.34.1 From b36ce57290bfa7c44ad1748095b7b89983768ffd Mon Sep 17 00:00:00 2001 From: Mikhail Zelenyy Date: Wed, 6 Nov 2019 16:10:43 +0300 Subject: [PATCH 3/6] Add test for checking data size in DF02 and DF03 --- .../hep/dataforge/io/FileEnvelopeTest.kt | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/dataforge-io/src/jvmTest/kotlin/hep/dataforge/io/FileEnvelopeTest.kt b/dataforge-io/src/jvmTest/kotlin/hep/dataforge/io/FileEnvelopeTest.kt index 46643ef2..33c07f66 100644 --- a/dataforge-io/src/jvmTest/kotlin/hep/dataforge/io/FileEnvelopeTest.kt +++ b/dataforge-io/src/jvmTest/kotlin/hep/dataforge/io/FileEnvelopeTest.kt @@ -1,9 +1,13 @@ package hep.dataforge.io import hep.dataforge.context.Global +import java.nio.ByteBuffer import java.nio.file.Files +import java.util.* import kotlin.test.Test +import kotlin.test.assertEquals import kotlin.test.assertTrue +import kotlin.test.fail class FileEnvelopeTest { @@ -61,4 +65,36 @@ class FileEnvelopeTest { assertTrue { envelope.contentEquals(restored) } } + @Test + fun testDataSize() { + val tmpPath = Files.createTempFile("dataforge_test", ".df") + Global.io.writeEnvelopeFile(tmpPath, envelope) + println(tmpPath.toUri()) + val scan = Scanner(tmpPath.toFile().inputStream()).useDelimiter("\n").nextLine() + println(scan) + val format = scan.slice(2..5) + when (format) { + "DF03" -> { + val buff = ByteBuffer.allocate(4) + buff.put(scan.slice(12..19).toByteArray()) + buff.flip() + val size = buff.long + println(size) + assertEquals(8, size) + } + "DF02" -> { + val buff = ByteBuffer.allocate(4) + buff.put(scan.slice(12..15).toByteArray()) + buff.flip() + val size = buff.int + println(size) + assertEquals(8, size) + } + else -> { + fail("Format $format don't have test") + } + } + } + + } \ No newline at end of file -- 2.34.1 From 31526c90e1ebafed3edac7bbf94e1b04f1d27eb6 Mon Sep 17 00:00:00 2001 From: Mikhail Zelenyy Date: Wed, 6 Nov 2019 16:23:33 +0300 Subject: [PATCH 4/6] Minor fix --- .../kotlin/hep/dataforge/workspace/WorkspaceBuilder.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dataforge-workspace/src/commonMain/kotlin/hep/dataforge/workspace/WorkspaceBuilder.kt b/dataforge-workspace/src/commonMain/kotlin/hep/dataforge/workspace/WorkspaceBuilder.kt index 2f717f78..b8f3ffa0 100644 --- a/dataforge-workspace/src/commonMain/kotlin/hep/dataforge/workspace/WorkspaceBuilder.kt +++ b/dataforge-workspace/src/commonMain/kotlin/hep/dataforge/workspace/WorkspaceBuilder.kt @@ -12,7 +12,7 @@ import hep.dataforge.names.toName import kotlin.jvm.JvmName import kotlin.reflect.KClass -@TaskBuildScope +@DFBuilder interface WorkspaceBuilder { val parentContext: Context var context: Context -- 2.34.1 From 1dd2b689ca4eb3e1b6af6a05132838abe5346437 Mon Sep 17 00:00:00 2001 From: Mikhail Zelenyy Date: Tue, 19 Nov 2019 18:05:23 +0300 Subject: [PATCH 5/6] Commit before merge, two test failed --- .../kotlin/hep/dataforge/io/FileBinaryTest.kt | 27 +++++++++++++++++++ .../hep/dataforge/io/FileEnvelopeTest.kt | 8 +++--- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/dataforge-io/src/jvmTest/kotlin/hep/dataforge/io/FileBinaryTest.kt b/dataforge-io/src/jvmTest/kotlin/hep/dataforge/io/FileBinaryTest.kt index d8c7c67a..8a31346a 100644 --- a/dataforge-io/src/jvmTest/kotlin/hep/dataforge/io/FileBinaryTest.kt +++ b/dataforge-io/src/jvmTest/kotlin/hep/dataforge/io/FileBinaryTest.kt @@ -4,6 +4,7 @@ import hep.dataforge.context.Global import java.nio.file.Files import kotlin.test.Test import kotlin.test.assertEquals +import kotlin.test.assertTrue class FileBinaryTest { val envelope = Envelope { @@ -53,4 +54,30 @@ class FileBinaryTest { assertEquals(binary.size.toInt(), binary.toBytes().size) } + @Test + fun testMultyPartFileData() { + val envelopeList = (0..5).map { + val dataFile = Files.createTempFile("dataforge_test_bin_$it", ".bin") + dataFile.toFile().writeText(DoubleArray(80000) { it.toDouble() }.joinToString()) + val envelopeFromFile = Envelope { + meta { + "a" put "AAA" + "b" put 22.2 + } + dataType = "hep.dataforge.satellite" + dataID = "cellDepositTest$it" // добавил только что + data = dataFile.asBinary() + } + envelopeFromFile + } + + val envelope = Envelope { + multipart(TaggedEnvelopeFormat, envelopeList) + } + println(envelopeList.map { it.data?.size }.joinToString(" ")) + println(envelope.data?.size) + assertTrue { envelope.data!!.size > envelopeList.map { it.data!!.size }.sum() } + + } + } \ No newline at end of file diff --git a/dataforge-io/src/jvmTest/kotlin/hep/dataforge/io/FileEnvelopeTest.kt b/dataforge-io/src/jvmTest/kotlin/hep/dataforge/io/FileEnvelopeTest.kt index ea67fffd..595ca619 100644 --- a/dataforge-io/src/jvmTest/kotlin/hep/dataforge/io/FileEnvelopeTest.kt +++ b/dataforge-io/src/jvmTest/kotlin/hep/dataforge/io/FileEnvelopeTest.kt @@ -45,23 +45,23 @@ class FileEnvelopeTest { val tmpPath = Files.createTempFile("dataforge_test", ".df") Global.io.writeEnvelopeFile(tmpPath, envelope) println(tmpPath.toUri()) - val restored: Envelope = Global.io.readEnvelopeFile(tmpPath) + val restored: Envelope = Global.io.readEnvelopeFile(tmpPath)!! assertTrue { envelope.contentEquals(restored) } } @Test fun testFileWriteTagless() { val tmpPath = Files.createTempFile("dataforge_test", ".df") - Global.io.writeEnvelopeFile(tmpPath, envelope, formatFactory = TaglessEnvelopeFormat) + Global.io.writeEnvelopeFile(tmpPath, envelope, format = TaglessEnvelopeFormat) assertTrue { tmpPath.toFile().length() > 0 } } @Test fun testFileWriteReadTagless() { val tmpPath = Files.createTempFile("dataforge_test", ".df") - Global.io.writeEnvelopeFile(tmpPath, envelope, formatFactory = TaglessEnvelopeFormat) + Global.io.writeEnvelopeFile(tmpPath, envelope, format = TaglessEnvelopeFormat) println(tmpPath.toUri()) - val restored: Envelope = Global.io.readEnvelopeFile(tmpPath, formatFactory = TaglessEnvelopeFormat) + val restored: Envelope = Global.io.readEnvelopeFile(tmpPath)!! assertTrue { envelope.contentEquals(restored) } } -- 2.34.1 From 7e749926019b4c34e6c191350773aace9d0aabc9 Mon Sep 17 00:00:00 2001 From: Mikhail Zelenyy Date: Tue, 19 Nov 2019 18:43:14 +0300 Subject: [PATCH 6/6] Fixed merge error --- .../kotlin/hep/dataforge/io/FileEnvelopeTest.kt | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/dataforge-io/src/jvmTest/kotlin/hep/dataforge/io/FileEnvelopeTest.kt b/dataforge-io/src/jvmTest/kotlin/hep/dataforge/io/FileEnvelopeTest.kt index ccd9fb60..f77e4903 100644 --- a/dataforge-io/src/jvmTest/kotlin/hep/dataforge/io/FileEnvelopeTest.kt +++ b/dataforge-io/src/jvmTest/kotlin/hep/dataforge/io/FileEnvelopeTest.kt @@ -35,17 +35,6 @@ class FileEnvelopeTest { } } - @Test - fun testFileWriteReadTagless() { - Global.io.run { - val tmpPath = Files.createTempFile("dataforge_test_tagless", ".df") - writeEnvelopeFile(tmpPath, envelope, envelopeFormat = TaglessEnvelopeFormat) - println(tmpPath.toUri()) - val restored: Envelope = readEnvelopeFile(tmpPath)!! - assertTrue { envelope.contentEquals(restored) } - } - } - @Test fun testFileWriteTagged() { val tmpPath = Files.createTempFile("dataforge_test", ".df") @@ -65,14 +54,14 @@ class FileEnvelopeTest { @Test fun testFileWriteTagless() { val tmpPath = Files.createTempFile("dataforge_test", ".df") - Global.io.writeEnvelopeFile(tmpPath, envelope, format = TaglessEnvelopeFormat) + Global.io.writeEnvelopeFile(tmpPath, envelope, envelopeFormat = TaglessEnvelopeFormat) assertTrue { tmpPath.toFile().length() > 0 } } @Test fun testFileWriteReadTagless() { val tmpPath = Files.createTempFile("dataforge_test", ".df") - Global.io.writeEnvelopeFile(tmpPath, envelope, format = TaglessEnvelopeFormat) + Global.io.writeEnvelopeFile(tmpPath, envelope, envelopeFormat = TaglessEnvelopeFormat) println(tmpPath.toUri()) val restored: Envelope = Global.io.readEnvelopeFile(tmpPath)!! assertTrue { envelope.contentEquals(restored) } -- 2.34.1