Rework beacon connection and implement various improvements

This commit is contained in:
Christopher Schnick
2022-03-07 22:59:48 +01:00
parent 46e83ae757
commit f5cccd5687
29 changed files with 386 additions and 117 deletions

View File

@@ -6,7 +6,14 @@ import io.xpipe.beacon.BeaconServer;
public class ConnectionFactory {
private static boolean alreadyStarted;
public static void start() throws Exception {
if (BeaconServer.isRunning()) {
alreadyStarted = true;
return;
}
if (!BeaconServer.tryStart()) {
throw new AssertionError();
}
@@ -18,6 +25,10 @@ public class ConnectionFactory {
}
public static void stop() throws Exception {
if (alreadyStarted) {
return;
}
if (!BeaconServer.isRunning()) {
return;
}

View File

@@ -6,12 +6,12 @@ import org.junit.jupiter.api.BeforeAll;
public class DaemonControl {
@BeforeAll
static void setup() throws Exception {
public static void setup() throws Exception {
ConnectionFactory.start();
}
@AfterAll
static void teardown() throws Exception {
public static void teardown() throws Exception {
ConnectionFactory.stop();
}
}

View File

@@ -0,0 +1,33 @@
package io.xpipe.api.test;
import io.xpipe.api.DataTableAccumulator;
import io.xpipe.core.data.node.TupleNode;
import io.xpipe.core.data.node.ValueNode;
import io.xpipe.core.data.type.TupleType;
import io.xpipe.core.data.type.ValueType;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.List;
import java.util.OptionalInt;
public class DataTableAccumulatorTest extends DaemonControl {
@Test
public void test() {
var type = TupleType.of(
List.of("col1", "col2"),
List.of(ValueType.of(), ValueType.of()));
var acc = DataTableAccumulator.create(type);
var val = type.convert(
TupleNode.of(List.of(ValueNode.of("val1"), ValueNode.of("val2")))).orElseThrow();
acc.add(val);
var table = acc.finish(":test");
Assertions.assertEquals(table.getInfo().getDataType(), TupleType.tableType(List.of("col1", "col2")));
Assertions.assertEquals(table.getInfo().getRowCountIfPresent(), OptionalInt.empty());
var read = table.read(1).at(0);
Assertions.assertEquals(val, read);
}
}

View File

@@ -10,7 +10,7 @@ import java.util.Map;
public class DataTableTest extends DaemonControl {
@BeforeAll
static void setup() throws Exception {
public static void setupStorage() throws Exception {
DataSource.create(DataSourceId.fromString(":usernames"), "csv", Map.of(), DataTableTest.class.getResource("username.csv"));
}