From 91a2ece422dc2ce3a1bd877fdfa191488d60e4fd Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 6 Nov 2024 01:30:15 +0000 Subject: [PATCH] reformat --- .../net/discdd/bundletransport/RpcServer.java | 2 +- .../bundletransport/ServerUploadFragment.java | 2 +- .../TransportWifiDirectService.java | 1 + .../net/discdd/pathutils/TransportPaths.java | 1 + .../TransportToBundleServerManager.java | 17 +-- .../BundleTransportToBundleServerTest.java | 109 ++++++++++++------ 6 files changed, 84 insertions(+), 48 deletions(-) diff --git a/BundleTransport/app/src/main/java/net/discdd/bundletransport/RpcServer.java b/BundleTransport/app/src/main/java/net/discdd/bundletransport/RpcServer.java index 6baaf614c5..36c01fec35 100644 --- a/BundleTransport/app/src/main/java/net/discdd/bundletransport/RpcServer.java +++ b/BundleTransport/app/src/main/java/net/discdd/bundletransport/RpcServer.java @@ -53,7 +53,7 @@ protected void onBundleExchangeEvent(BundleExchangeEvent bundleExchangeEvent) { @Override protected Path pathProducer(BundleExchangeName bundleExchangeName, BundleSender bundleSender) { return bundleExchangeName.isDownload() ? toClientPath.resolve(bundleExchangeName.encryptedBundleId()) : - toServerPath.resolve(bundleExchangeName.encryptedBundleId()); + toServerPath.resolve(bundleExchangeName.encryptedBundleId()); } @Override diff --git a/BundleTransport/app/src/main/java/net/discdd/bundletransport/ServerUploadFragment.java b/BundleTransport/app/src/main/java/net/discdd/bundletransport/ServerUploadFragment.java index fb42785174..5844e7f578 100644 --- a/BundleTransport/app/src/main/java/net/discdd/bundletransport/ServerUploadFragment.java +++ b/BundleTransport/app/src/main/java/net/discdd/bundletransport/ServerUploadFragment.java @@ -22,6 +22,7 @@ import java.util.concurrent.Executors; import java.util.concurrent.SubmissionPublisher; import java.util.logging.Logger; + import net.discdd.transport.TransportToBundleServerManager; /** @@ -173,7 +174,6 @@ private Void connectToServerError(Exception e, String transportTarget) { return null; } - private void appendToActivityLog(String message) { requireActivity().runOnUiThread(() -> { if (serverConnnectedStatus.getLineCount() > 20) { diff --git a/BundleTransport/app/src/main/java/net/discdd/bundletransport/TransportWifiDirectService.java b/BundleTransport/app/src/main/java/net/discdd/bundletransport/TransportWifiDirectService.java index ef6c739814..0809498c72 100644 --- a/BundleTransport/app/src/main/java/net/discdd/bundletransport/TransportWifiDirectService.java +++ b/BundleTransport/app/src/main/java/net/discdd/bundletransport/TransportWifiDirectService.java @@ -1,6 +1,7 @@ package net.discdd.bundletransport; import android.content.Context; + import static java.util.logging.Level.INFO; import static java.util.logging.Level.SEVERE; diff --git a/bundle-core/src/main/java/net/discdd/pathutils/TransportPaths.java b/bundle-core/src/main/java/net/discdd/pathutils/TransportPaths.java index 52288ba066..b9691430c4 100644 --- a/bundle-core/src/main/java/net/discdd/pathutils/TransportPaths.java +++ b/bundle-core/src/main/java/net/discdd/pathutils/TransportPaths.java @@ -3,6 +3,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.logging.Logger; + import static java.util.logging.Level.SEVERE; // BundleTransport diff --git a/bundle-core/src/main/java/net/discdd/transport/TransportToBundleServerManager.java b/bundle-core/src/main/java/net/discdd/transport/TransportToBundleServerManager.java index c9662ccc2e..8fbf504818 100644 --- a/bundle-core/src/main/java/net/discdd/transport/TransportToBundleServerManager.java +++ b/bundle-core/src/main/java/net/discdd/transport/TransportToBundleServerManager.java @@ -101,9 +101,8 @@ public void run() { private void processRecencyBlob(BundleExchangeServiceGrpc.BundleExchangeServiceBlockingStub blockingExchangeStub) { var recencyBlobReq = GetRecencyBlobRequest.newBuilder().setSender(transportSenderId).build(); - var recencyBlob = - blockingExchangeStub.withDeadlineAfter(Constants.GRPC_SHORT_TIMEOUT_MS, TimeUnit.MILLISECONDS) - .getRecencyBlob(recencyBlobReq); + var recencyBlob = blockingExchangeStub.withDeadlineAfter(Constants.GRPC_SHORT_TIMEOUT_MS, TimeUnit.MILLISECONDS) + .getRecencyBlob(recencyBlobReq); Path blobPath = fromServerPath.resolve(RECENCY_BLOB_BIN); try (var os = Files.newOutputStream(blobPath, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) { @@ -114,15 +113,16 @@ private void processRecencyBlob(BundleExchangeServiceGrpc.BundleExchangeServiceB } } - private void processDownloadBundles(List bundlesToDownloadList, BundleExchangeServiceGrpc.BundleExchangeServiceStub exchangeStub) { + private void processDownloadBundles(List bundlesToDownloadList, + BundleExchangeServiceGrpc.BundleExchangeServiceStub exchangeStub) { for (var toReceive : bundlesToDownloadList) { var path = fromServerPath.resolve(toReceive.getEncryptedId()); try (OutputStream os = Files.newOutputStream(path, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) { var completion = new CompletableFuture(); - exchangeStub.withDeadlineAfter(Constants.GRPC_LONG_TIMEOUT_MS, TimeUnit.MILLISECONDS) - .downloadBundle(BundleDownloadRequest.newBuilder().setBundleId(toReceive) - .setSender(transportSenderId).build(), new StreamObserver<>() { + exchangeStub.withDeadlineAfter(Constants.GRPC_LONG_TIMEOUT_MS, TimeUnit.MILLISECONDS).downloadBundle( + BundleDownloadRequest.newBuilder().setBundleId(toReceive).setSender(transportSenderId).build(), + new StreamObserver<>() { @Override public void onNext(BundleDownloadResponse value) { try { @@ -153,7 +153,8 @@ public void onCompleted() { } } - private void processUploadBundles(List bundlesToUploadList, BundleExchangeServiceGrpc.BundleExchangeServiceStub exchangeStub) { + private void processUploadBundles(List bundlesToUploadList, + BundleExchangeServiceGrpc.BundleExchangeServiceStub exchangeStub) { for (var toSend : bundlesToUploadList) { var path = fromClientPath.resolve(toSend.getEncryptedId()); StreamObserver responseObserver = null; diff --git a/bundleserver/src/test/java/net/discdd/server/BundleTransportToBundleServerTest.java b/bundleserver/src/test/java/net/discdd/server/BundleTransportToBundleServerTest.java index 50084d560a..4cc42dc5e2 100644 --- a/bundleserver/src/test/java/net/discdd/server/BundleTransportToBundleServerTest.java +++ b/bundleserver/src/test/java/net/discdd/server/BundleTransportToBundleServerTest.java @@ -28,7 +28,8 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; -@SpringBootTest(classes = {BundleServerApplication.class, End2EndTest.End2EndTestInitializer.class}) + +@SpringBootTest(classes = { BundleServerApplication.class, End2EndTest.End2EndTestInitializer.class }) @TestMethodOrder(MethodOrderer.MethodName.class) public class BundleTransportToBundleServerTest extends End2EndTest { private static final Logger logger = Logger.getLogger(BundleTransportToBundleServerTest.class.getName()); @@ -47,13 +48,14 @@ void setUp() { toClientPath = transportPaths.toClientPath; toServerPath = transportPaths.toServerPath; - manager = new TransportToBundleServerManager( - transportPaths, - "localhost", - Integer.toString(BUNDLESERVER_GRPC_PORT), - (Void) -> {System.out.println("connectComplete"); return null;}, - (Exception e) -> {System.out.println("connectError"); return null;} - ); + manager = new TransportToBundleServerManager(transportPaths, "localhost", + Integer.toString(BUNDLESERVER_GRPC_PORT), (Void) -> { + System.out.println("connectComplete"); + return null; + }, (Exception e) -> { + System.out.println("connectError"); + return null; + }); } @BeforeEach @@ -79,8 +81,7 @@ void tearDownEach() throws IOException { private void recursiveDelete(Path path) throws IOException { if (Files.exists(path)) { - Files.walk(path) - .sorted(Comparator.reverseOrder()) // Delete files before directories + Files.walk(path).sorted(Comparator.reverseOrder()) // Delete files before directories .forEach(file -> { try { Files.deleteIfExists(file); @@ -117,9 +118,11 @@ void testRun() throws IOException { } @Test - void testRecencyBlob() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, IOException { + void testRecencyBlob() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, + IOException { // Prepare to process recency blob - Method processRecencyBlob = TransportToBundleServerManager.class.getDeclaredMethod("processRecencyBlob", BundleExchangeServiceGrpc.BundleExchangeServiceBlockingStub.class); + Method processRecencyBlob = TransportToBundleServerManager.class.getDeclaredMethod("processRecencyBlob", + BundleExchangeServiceGrpc.BundleExchangeServiceBlockingStub.class); processRecencyBlob.setAccessible(true); processRecencyBlob.invoke(manager, blockingStub); @@ -139,26 +142,32 @@ void testRecencyBlob() throws NoSuchMethodException, InvocationTargetException, logger.info("Recency Blob last modified time: " + lastModifiedTime); long currentTime = System.currentTimeMillis(); long lastModifiedMillis = lastModifiedTime.toMillis(); - assertTrue((currentTime - lastModifiedMillis) < 50000, "Recency Blob should have been modified within the last 5 seconds."); + assertTrue((currentTime - lastModifiedMillis) < 50000, + "Recency Blob should have been modified within the last 5 seconds."); } @Test - void testUploadBundles() throws IOException, NoSuchMethodException, InvocationTargetException, IllegalAccessException { + void testUploadBundles() throws IOException, NoSuchMethodException, InvocationTargetException, + IllegalAccessException { // Create files on client side Files.createFile(toServerPath.resolve("bundle1")); Files.createFile(toServerPath.resolve("bundle2")); Files.createFile(toServerPath.resolve("bundle3")); - Method populateListFromPath = TransportToBundleServerManager.class.getDeclaredMethod("populateListFromPath", Path.class); + Method populateListFromPath = + TransportToBundleServerManager.class.getDeclaredMethod("populateListFromPath", Path.class); populateListFromPath.setAccessible(true); // Retrieve the bundles from the client - List bundlesToUpload = (List) populateListFromPath.invoke(manager, toServerPath); + List bundlesToUpload = + (List) populateListFromPath.invoke(manager, toServerPath); // Assert that bundles are successfully added to /server path assertEquals(3, bundlesToUpload.size(), "The number of bundles should be 3."); // Prepare to upload the bundles - Method processUploadBundles = TransportToBundleServerManager.class.getDeclaredMethod("processUploadBundles", List.class, BundleExchangeServiceGrpc.BundleExchangeServiceStub.class); + Method processUploadBundles = + TransportToBundleServerManager.class.getDeclaredMethod("processUploadBundles", List.class, + BundleExchangeServiceGrpc.BundleExchangeServiceStub.class); processUploadBundles.setAccessible(true); // Upload all bundles @@ -167,29 +176,35 @@ void testUploadBundles() throws IOException, NoSuchMethodException, InvocationTa // Check that the bundles were uploaded to server for (EncryptedBundleId toUpload : bundlesToUpload) { Path uploadPath = toServerPath.resolve(toUpload.getEncryptedId()); - assertFalse(Files.exists(uploadPath), toUpload.getEncryptedId() + " should have been deleted after upload."); + assertFalse(Files.exists(uploadPath), + toUpload.getEncryptedId() + " should have been deleted after upload."); } assertEquals(0, Files.list(toServerPath).count()); } @Test - void testDownloadBundles() throws IOException, NoSuchMethodException, InvocationTargetException, IllegalAccessException { + void testDownloadBundles() throws IOException, NoSuchMethodException, InvocationTargetException, + IllegalAccessException { // Create files on server side Files.createFile(toClientPath.resolve("bundle1")); Files.createFile(toClientPath.resolve("bundle2")); Files.createFile(toClientPath.resolve("bundle3")); - Method populateListFromPath = TransportToBundleServerManager.class.getDeclaredMethod("populateListFromPath", Path.class); + Method populateListFromPath = + TransportToBundleServerManager.class.getDeclaredMethod("populateListFromPath", Path.class); populateListFromPath.setAccessible(true); // Retrieve the bundles from the server - List bundlesToDownload = (List) populateListFromPath.invoke(manager, toClientPath); + List bundlesToDownload = + (List) populateListFromPath.invoke(manager, toClientPath); // Assert that bundles are successfully created assertEquals(3, bundlesToDownload.size(), "The number of bundles should be 3."); // Prepare to download the bundles - Method processDownloadBundles = TransportToBundleServerManager.class.getDeclaredMethod("processDownloadBundles", List.class, BundleExchangeServiceGrpc.BundleExchangeServiceStub.class); + Method processDownloadBundles = + TransportToBundleServerManager.class.getDeclaredMethod("processDownloadBundles", List.class, + BundleExchangeServiceGrpc.BundleExchangeServiceStub.class); processDownloadBundles.setAccessible(true); // Download all bundles from the server @@ -211,11 +226,15 @@ void testDownloadWithSendingBundles() throws Exception { Files.createFile(toSendDir.resolve("bundle2")); Files.createFile(toSendDir.resolve("bundle3")); - Method populateListFromPath = TransportToBundleServerManager.class.getDeclaredMethod("populateListFromPath", Path.class); + Method populateListFromPath = + TransportToBundleServerManager.class.getDeclaredMethod("populateListFromPath", Path.class); populateListFromPath.setAccessible(true); - List bundlesToDownload = (List) populateListFromPath.invoke(manager, toSendDir); + List bundlesToDownload = + (List) populateListFromPath.invoke(manager, toSendDir); - Method processDownloadBundles = TransportToBundleServerManager.class.getDeclaredMethod("processDownloadBundles", List.class, BundleExchangeServiceGrpc.BundleExchangeServiceStub.class); + Method processDownloadBundles = + TransportToBundleServerManager.class.getDeclaredMethod("processDownloadBundles", List.class, + BundleExchangeServiceGrpc.BundleExchangeServiceStub.class); processDownloadBundles.setAccessible(true); processDownloadBundles.invoke(manager, bundlesToDownload, stub); @@ -223,7 +242,8 @@ void testDownloadWithSendingBundles() throws Exception { // check if /client contains those EncryptedBundleIds for (EncryptedBundleId toDownload : bundlesToDownload) { Path downloadPath = toClientPath.resolve(toDownload.getEncryptedId()); - assertTrue(Files.exists(downloadPath), toDownload.getEncryptedId() + " should have been sent and downloaded."); + assertTrue(Files.exists(downloadPath), + toDownload.getEncryptedId() + " should have been sent and downloaded."); } assertEquals(3, Files.list(toClientPath).count()); } @@ -234,17 +254,20 @@ void testDeleteBundles() throws Exception { Files.createFile(toClientPath.resolve("bundle1")); Files.createFile(toClientPath.resolve("bundle2")); Files.createFile(toClientPath.resolve("bundle3")); - Method populateListFromPath = TransportToBundleServerManager.class.getDeclaredMethod("populateListFromPath", Path.class); + Method populateListFromPath = + TransportToBundleServerManager.class.getDeclaredMethod("populateListFromPath", Path.class); populateListFromPath.setAccessible(true); // Retrieve the bundles from the server - List bundlesToDelete = (List) populateListFromPath.invoke(manager, toClientPath); + List bundlesToDelete = + (List) populateListFromPath.invoke(manager, toClientPath); // Assert that bundles are successfully added to /client path assertEquals(3, bundlesToDelete.size(), "The number of bundles should be 3."); // Prepare to delete bundles - Method processDeleteBundles = TransportToBundleServerManager.class.getDeclaredMethod("processDeleteBundles", List.class); + Method processDeleteBundles = + TransportToBundleServerManager.class.getDeclaredMethod("processDeleteBundles", List.class); processDeleteBundles.setAccessible(true); // Delete all bundles @@ -253,21 +276,26 @@ void testDeleteBundles() throws Exception { // Assert that the bundles have been deleted on client side for (EncryptedBundleId toDelete : bundlesToDelete) { Path deletePath = toClientPath.resolve(toDelete.getEncryptedId()); - assertFalse(Files.exists(deletePath), toDelete.getEncryptedId() + " should be deleted: " + deletePath); + assertFalse(Files.exists(deletePath), toDelete.getEncryptedId() + " should be deleted: " + deletePath); } } @Test - void testUploadNonExistentBundle() throws InvocationTargetException, IllegalAccessException, IOException, NoSuchMethodException { - Method populateListFromPath = TransportToBundleServerManager.class.getDeclaredMethod("populateListFromPath", Path.class); + void testUploadNonExistentBundle() throws InvocationTargetException, IllegalAccessException, IOException, + NoSuchMethodException { + Method populateListFromPath = + TransportToBundleServerManager.class.getDeclaredMethod("populateListFromPath", Path.class); populateListFromPath.setAccessible(true); // Retrieve the bundles from the empty directory - List bundlesToUpload = (List) populateListFromPath.invoke(manager, toServerPath); + List bundlesToUpload = + (List) populateListFromPath.invoke(manager, toServerPath); assertTrue(bundlesToUpload.isEmpty(), "The list of bundles should be empty."); // Attempt to upload bundles - Method processUploadBundles = TransportToBundleServerManager.class.getDeclaredMethod("processUploadBundles", List.class, BundleExchangeServiceGrpc.BundleExchangeServiceStub.class); + Method processUploadBundles = + TransportToBundleServerManager.class.getDeclaredMethod("processUploadBundles", List.class, + BundleExchangeServiceGrpc.BundleExchangeServiceStub.class); processUploadBundles.setAccessible(true); processUploadBundles.invoke(manager, bundlesToUpload, stub); @@ -276,16 +304,21 @@ void testUploadNonExistentBundle() throws InvocationTargetException, IllegalAcce } @Test - void testDownloadNonExistentBundle() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, IOException { - Method populateListFromPath = TransportToBundleServerManager.class.getDeclaredMethod("populateListFromPath", Path.class); + void testDownloadNonExistentBundle() throws NoSuchMethodException, InvocationTargetException, + IllegalAccessException, IOException { + Method populateListFromPath = + TransportToBundleServerManager.class.getDeclaredMethod("populateListFromPath", Path.class); populateListFromPath.setAccessible(true); // Retrieve the bundles from the empty directory - List bundlesToDownload = (List) populateListFromPath.invoke(manager, toClientPath); + List bundlesToDownload = + (List) populateListFromPath.invoke(manager, toClientPath); assertTrue(bundlesToDownload.isEmpty(), "The list of bundles should be empty."); // Attempt to download bundles - Method processDownloadBundles = TransportToBundleServerManager.class.getDeclaredMethod("processDownloadBundles", List.class, BundleExchangeServiceGrpc.BundleExchangeServiceStub.class); + Method processDownloadBundles = + TransportToBundleServerManager.class.getDeclaredMethod("processDownloadBundles", List.class, + BundleExchangeServiceGrpc.BundleExchangeServiceStub.class); processDownloadBundles.setAccessible(true); processDownloadBundles.invoke(manager, bundlesToDownload, stub);