mirror of
https://github.com/xpipe-io/xpipe.git
synced 2026-04-29 02:45:33 -04:00
Rework beacon connection and implement various improvements
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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"));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user