Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Writesamplestwice #9

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ public CleanableFileChannel writeFileChannel() throws IOException {
* @param estimateNumber the number to write.
*/
public void writeEstimate(Number estimateNumber) {
if (this.been_used) {
throw (new RuntimeException("obj component already written"));
}
var estimate =
ImmutableEstimate.builder().internalValue(estimateNumber).rng(this.dp.coderun.rng).build();

Expand All @@ -72,6 +75,7 @@ public void writeEstimate(Number estimateNumber) {
} catch (IOException e) {
throw (new RuntimeException("writeEstimate() -- IOException trying to write to file.", e));
}
this.been_used = true;
}

/**
Expand All @@ -80,12 +84,16 @@ public void writeEstimate(Number estimateNumber) {
* @param distribution the Distribution to write
*/
public void writeDistribution(Distribution distribution) {
if (this.been_used) {
throw (new RuntimeException("obj component already written"));
}
try (CleanableFileChannel fileChannel = this.getFileChannel()) {
this.dp.coderun.parameterDataWriter.write(fileChannel, this.component_name, distribution);
} catch (IOException e) {
throw (new RuntimeException(
"writeDistribution() -- IOException trying to write to file.", e));
}
this.been_used = true;
}

/**
Expand All @@ -94,11 +102,15 @@ public void writeDistribution(Distribution distribution) {
* @param samples a Samples object containing the samples
*/
public void writeSamples(Samples samples) {
if (this.been_used) {
throw (new RuntimeException("obj component already written"));
}
try (CleanableFileChannel fileChannel = this.getFileChannel()) {
this.dp.coderun.parameterDataWriter.write(fileChannel, this.component_name, samples);
} catch (IOException e) {
throw (new RuntimeException("writeSamples() -- IOException trying to write to file.", e));
}
this.been_used = true;
}

void register_me_in_code_run() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -323,6 +324,19 @@ void check_last_coderun(
}
}

@Test
@Order(1)
void testWriteEstimateFail() {
String dataProduct = "human/population2";
String component = "estimate-component";
try (Coderun coderun = new Coderun(configPath, scriptPath, token)) {
Data_product_write dp = coderun.get_dp_for_write(dataProduct, "toml");
Object_component_write oc = dp.getComponent(component);
oc.writeEstimate(estimate);
assertThrows(RuntimeException.class, () -> oc.writeEstimate(estimate));
}
}

@Test
@Order(1)
void testWriteEstimate() {
Expand Down Expand Up @@ -379,6 +393,19 @@ void testReadDistribution() {
check_last_coderun(List.of(new Triplet<>(dataProduct, component, hash)), null);
}

@Test
@Order(5)
void testWriteCategoricalDistributionFail() {
String dataProduct = "human/cdistribution2";
String component = "cdistribution-component";
try (var coderun = new Coderun(configPath, scriptPath, token)) {
Data_product_write dp = coderun.get_dp_for_write(dataProduct, "toml");
Object_component_write oc = dp.getComponent(component);
oc.writeDistribution(categoricalDistribution);
assertThrows(RuntimeException.class, () -> oc.writeDistribution(distribution));
}
}

@Test
@Order(5)
void testWriteCategoricalDistribution() {
Expand Down Expand Up @@ -407,6 +434,19 @@ void testReadCategoricalDistribution() {
check_last_coderun(List.of(new Triplet<>(dataProduct, component, hash)), null);
}

@Test
@Order(7)
void testWriteSamplesFail() throws RuntimeException {
String dataProduct = "human/samples2";
String component = "example-samples-w";
try (var coderun = new Coderun(configPath, scriptPath, token)) {
Data_product_write dp = coderun.get_dp_for_write(dataProduct, "toml");
Object_component_write oc = dp.getComponent(component);
oc.writeSamples(samples2);
assertThrows(RuntimeException.class, () -> oc.writeSamples(samples3));
}
}

@Test
@Order(7)
void testWriteSamples() {
Expand Down
12 changes: 12 additions & 0 deletions api/src/test/resources/config-stdapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ read:
version: 0.0.1

write:
- data_product: human/population2
description: Coderun Integration test
use:
version: 0.0.1
- data_product: human/population
description: Coderun Integration test
use:
Expand All @@ -58,6 +62,10 @@ write:
description: Coderun Integration test for distribution
use:
version: 0.0.1
- data_product: human/cdistribution2
description: Coderun Integration test for cdistribution
use:
version: 0.0.1
- data_product: human/cdistribution
description: Coderun Integration test for cdistribution
use:
Expand All @@ -66,6 +74,10 @@ write:
description: Coderun Integration test for samples
use:
version: 0.0.1
- data_product: human/samples2
description: Coderun Integration test for samples
use:
version: 0.0.1
- data_product: human/multicomp
description: Coderun Integration test for samples multiple components
use:
Expand Down
Loading