mirror of
https://github.com/xpipe-io/xpipe.git
synced 2026-04-24 16:40:58 -04:00
Rework beacon connections and flesh out API more
This commit is contained in:
31
api/src/test/java/io/xpipe/api/test/ConnectionFactory.java
Normal file
31
api/src/test/java/io/xpipe/api/test/ConnectionFactory.java
Normal 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();
|
||||
}
|
||||
}
|
||||
17
api/src/test/java/io/xpipe/api/test/DaemonControl.java
Normal file
17
api/src/test/java/io/xpipe/api/test/DaemonControl.java
Normal 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();
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user