Skip to content

Commit 36df9b6

Browse files
committed
disallow twice write to the same 'samples' component (toml)
1 parent 87b6a40 commit 36df9b6

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

api/src/main/java/org/fairdatapipeline/api/Object_component_write.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,15 @@ public void writeDistribution(Distribution distribution) {
9494
* @param samples a Samples object containing the samples
9595
*/
9696
public void writeSamples(Samples samples) {
97+
if(this.been_used) {
98+
throw(new RuntimeException("obj component already written"));
99+
}
97100
try (CleanableFileChannel fileChannel = this.getFileChannel()) {
98101
this.dp.coderun.parameterDataWriter.write(fileChannel, this.component_name, samples);
99102
} catch (IOException e) {
100103
throw (new RuntimeException("writeSamples() -- IOException trying to write to file.", e));
101104
}
105+
this.been_used = true;
102106
}
103107

104108
void register_me_in_code_run() {

api/src/test/java/org/fairdatapipeline/api/CoderunIntegrationTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import static org.assertj.core.api.Assertions.assertThat;
44
import static org.junit.jupiter.api.Assertions.*;
5+
import static org.junit.jupiter.api.Assertions.assertThrows;
6+
57
import static org.mockito.Mockito.mock;
68
import static org.mockito.Mockito.when;
79

@@ -407,6 +409,19 @@ void testReadCategoricalDistribution() {
407409
check_last_coderun(List.of(new Triplet<>(dataProduct, component, hash)), null);
408410
}
409411

412+
@Test
413+
@Order(7)
414+
void testWriteSamplesFail() throws RuntimeException {
415+
String dataProduct = "human/samples2";
416+
String component = "example-samples-w";
417+
try (var coderun = new Coderun(configPath, scriptPath, token)) {
418+
Data_product_write dp = coderun.get_dp_for_write(dataProduct, "toml");
419+
Object_component_write oc = dp.getComponent(component);
420+
oc.writeSamples(samples2);
421+
assertThrows(RuntimeException.class, () -> oc.writeSamples(samples3));
422+
}
423+
}
424+
410425
@Test
411426
@Order(7)
412427
void testWriteSamples() {

api/src/test/resources/config-stdapi.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ write:
6666
description: Coderun Integration test for samples
6767
use:
6868
version: 0.0.1
69+
- data_product: human/samples2
70+
description: Coderun Integration test for samples
71+
use:
72+
version: 0.0.1
6973
- data_product: human/multicomp
7074
description: Coderun Integration test for samples multiple components
7175
use:

0 commit comments

Comments
 (0)