Rework beacon connections and flesh out API more

This commit is contained in:
Christopher Schnick
2022-03-05 20:46:33 +01:00
parent 2c041ecb0e
commit 46e83ae757
37 changed files with 721 additions and 416 deletions

View File

@@ -0,0 +1,31 @@
package io.xpipe.api.test;
import io.xpipe.api.connector.XPipeConnection;
import io.xpipe.beacon.BeaconClient;
import io.xpipe.beacon.BeaconServer;
public class ConnectionFactory {
public static void start() throws Exception {
if (!BeaconServer.tryStart()) {
throw new AssertionError();
}
XPipeConnection.waitForStartup();
if (!BeaconServer.isRunning()) {
throw new AssertionError();
}
}
public static void stop() throws Exception {
if (!BeaconServer.isRunning()) {
return;
}
var client = new BeaconClient();
if (!BeaconServer.tryStop(client)) {
throw new AssertionError();
}
XPipeConnection.waitForShutdown();
}
}

View File

@@ -0,0 +1,17 @@
package io.xpipe.api.test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
public class DaemonControl {
@BeforeAll
static void setup() throws Exception {
ConnectionFactory.start();
}
@AfterAll
static void teardown() throws Exception {
ConnectionFactory.stop();
}
}

View File

@@ -1,16 +1,22 @@
package io.xpipe.api.test;
import io.xpipe.api.DataSource;
import io.xpipe.api.DataTable;
import io.xpipe.core.source.DataSourceId;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@ExtendWith({XPipeConfig.class})
public class DataTableTest {
import java.util.Map;
public class DataTableTest extends DaemonControl {
@BeforeAll
static void setup() throws Exception {
DataSource.create(DataSourceId.fromString(":usernames"), "csv", Map.of(), DataTableTest.class.getResource("username.csv"));
}
@Test
public void testGet() {
var table = DataSource.get("new folder:username").asTable();
var table = DataSource.getById(":usernames").asTable();
var r = table.read(2);
var a = 0;
}

View File

@@ -1,29 +0,0 @@
package io.xpipe.api.test;
import io.xpipe.beacon.BeaconClient;
import io.xpipe.beacon.BeaconServer;
import org.junit.jupiter.api.extension.BeforeAllCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
public class XPipeConfig implements BeforeAllCallback, ExtensionContext.Store.CloseableResource {
private static boolean started = false;
@Override
public void beforeAll(ExtensionContext context) throws Exception {
if (!started) {
started = true;
if (BeaconServer.tryStart()) {
throw new AssertionError();
}
}
}
@Override
public void close() throws Exception {
var client = new BeaconClient();
if (BeaconServer.tryStop(client)) {
throw new AssertionError();
}
}
}

View File

@@ -1,7 +1,9 @@
module io.xpipe.api.test {
exports io.xpipe.api.test;
requires io.xpipe.api;
requires io.xpipe.beacon;
requires org.junit.jupiter.api;
opens io.xpipe.api.test;
exports io.xpipe.api.test;
}