This is an automated email from the ASF dual-hosted git repository.
rpardomeza pushed a commit to branch profile-db
in repository https://gitbox.apache.org/repos/asf/incubator-wayang.git
The following commit(s) were added to refs/heads/profile-db by this push:
new a1c1ac8 [WAYANG-32] Tests and fixed
a1c1ac8 is described below
commit a1c1ac827f50b5f934c1fa7cd1ea3ea69e910822
Author: rodrigopardomeza <[email protected]>
AuthorDate: Mon Aug 30 19:37:09 2021 +0200
[WAYANG-32] Tests and fixed
---
.../src/main/java/profiledb/ProfileDB.java | 28 ++++++++++++++++++++++
.../src/main/java/profiledb/storage/Storage.java | 4 +++-
.../src/test/java/profiledb/ProfileDBTest.java | 24 ++++++++++++-------
3 files changed, 46 insertions(+), 10 deletions(-)
diff --git
a/wayang-commons/wayang-utils/wayang-profile-db/src/main/java/profiledb/ProfileDB.java
b/wayang-commons/wayang-utils/wayang-profile-db/src/main/java/profiledb/ProfileDB.java
index cd90d40..21490e9 100644
---
a/wayang-commons/wayang-utils/wayang-profile-db/src/main/java/profiledb/ProfileDB.java
+++
b/wayang-commons/wayang-utils/wayang-profile-db/src/main/java/profiledb/ProfileDB.java
@@ -40,6 +40,34 @@ public class ProfileDB {
*/
private Gson gson;
+ public void save(Experiment... experiments) throws IOException {
+ this.storage.save(experiments);
+ }
+
+ public void save(Collection<Experiment> experiments) throws IOException {
+ this.storage.save(experiments);
+ }
+
+ public void save(Collection<Experiment> experiments, OutputStream
outputStream) throws IOException {
+ this.storage.save(experiments, outputStream);
+ }
+
+ public void append(Experiment... experiments) throws IOException {
+ this.storage.append(experiments);
+ }
+
+ public void append(Collection<Experiment> experiments) throws IOException {
+ this.storage.append(experiments);
+ }
+
+ public Collection<Experiment> load() throws IOException {
+ return this.storage.load();
+ }
+
+ public Collection<Experiment> load(InputStream inputStream) throws
IOException {
+ return this.storage.load(inputStream);
+ }
+
/**
* Creates a new instance.
*/
diff --git
a/wayang-commons/wayang-utils/wayang-profile-db/src/main/java/profiledb/storage/Storage.java
b/wayang-commons/wayang-utils/wayang-profile-db/src/main/java/profiledb/storage/Storage.java
index cdda15b..b27aefc 100644
---
a/wayang-commons/wayang-utils/wayang-profile-db/src/main/java/profiledb/storage/Storage.java
+++
b/wayang-commons/wayang-utils/wayang-profile-db/src/main/java/profiledb/storage/Storage.java
@@ -47,7 +47,9 @@ public abstract class Storage {
this.storageFile = uri;
}
- public void save(Experiment... experiments) throws IOException {}
+ public void save(Experiment... experiments) throws IOException {
+ System.out.println("llegue");
+ }
public void save(Collection<Experiment> experiments) throws IOException {}
diff --git
a/wayang-commons/wayang-utils/wayang-profile-db/src/test/java/profiledb/ProfileDBTest.java
b/wayang-commons/wayang-utils/wayang-profile-db/src/test/java/profiledb/ProfileDBTest.java
index da05470..ea93bc7 100644
---
a/wayang-commons/wayang-utils/wayang-profile-db/src/test/java/profiledb/ProfileDBTest.java
+++
b/wayang-commons/wayang-utils/wayang-profile-db/src/test/java/profiledb/ProfileDBTest.java
@@ -16,6 +16,7 @@ import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Files;
+import java.nio.file.Paths;
import java.util.*;
public class ProfileDBTest {
@@ -52,7 +53,7 @@ public class ProfileDBTest {
*/
byte[] buffer;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
- profileDB.getStorage().save(Collections.singleton(experiment),
bos);
+ profileDB.save(Collections.singleton(experiment), bos);
bos.close();
buffer = bos.toByteArray();
System.out.println("Buffer contents: " + new String(buffer,
"UTF-8"));
@@ -62,7 +63,7 @@ public class ProfileDBTest {
* Lee el experimento desde el buffer en memoria
*/
ByteArrayInputStream bis = new ByteArrayInputStream(buffer);
- Collection<Experiment> loadedExperiments =
profileDB.getStorage().load(bis);
+ Collection<Experiment> loadedExperiments = profileDB.load(bis);
// Compare the experiments.
Assert.assertEquals(1, loadedExperiments.size());
@@ -102,14 +103,14 @@ public class ProfileDBTest {
// Save the experiment.
byte[] buffer;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
- profileDB.getStorage().save(Collections.singleton(experiment),
bos);
+ profileDB.save(Collections.singleton(experiment), bos);
bos.close();
buffer = bos.toByteArray();
System.out.println("Buffer contents: " + new String(buffer,
"UTF-8"));
// Load the experiment.
ByteArrayInputStream bis = new ByteArrayInputStream(buffer);
- Collection<Experiment> loadedExperiments =
profileDB.getStorage().load(bis);
+ Collection<Experiment> loadedExperiments = profileDB.load(bis);
// Compare the experiments.
Assert.assertEquals(1, loadedExperiments.size());
@@ -146,14 +147,18 @@ public class ProfileDBTest {
// Save the experiments.
File tempDir = Files.createTempDirectory("profiledb").toFile();
+ //File dir =
Files.createTempDirectory(Paths.get("/Users/rodrigopardomeza/Desktop/random/"),
"profiledb").toFile();
+ //File dir =
Paths.get("/Users/rodrigopardomeza/Desktop/random/").toFile();
File file = new File(tempDir, "profiledb.json");
- profileDB.getStorage().save(experiment1);
- profileDB.getStorage().append(experiment2, experiment3);
+ file.createNewFile();
+ profileDB.save(experiment1);
+ profileDB.append(experiment2, experiment3);
+ System.out.println("File plat" + file.toPath().toUri().toString());
Files.lines(file.toPath()).forEach(System.out::println);
// Load and compare.
- final Set<Experiment> loadedExperiments = new
HashSet<>(profileDB.getStorage().load());
+ final Set<Experiment> loadedExperiments = new
HashSet<>(profileDB.load());
final List<Experiment> expectedExperiments =
Arrays.asList(experiment1, experiment2, experiment3);
Assert.assertEquals(expectedExperiments.size(),
loadedExperiments.size());
Assert.assertEquals(new HashSet<>(expectedExperiments), new
HashSet<>(loadedExperiments));
@@ -181,13 +186,14 @@ public class ProfileDBTest {
// Save the experiments.
File tempDir = Files.createTempDirectory("profiledb").toFile();
File file = new File(tempDir, "new-profiledb.json");
+ file.createNewFile();
Assert.assertTrue(!file.exists() || file.delete());
- profileDB.getStorage().append(experiment1);
+ profileDB.append(experiment1);
Files.lines(file.toPath()).forEach(System.out::println);
// Load and compare.
- final Set<Experiment> loadedExperiments = new
HashSet<>(profileDB.getStorage().load());
+ final Set<Experiment> loadedExperiments = new
HashSet<>(profileDB.load());
final List<Experiment> expectedExperiments =
Collections.singletonList(experiment1);
Assert.assertEquals(expectedExperiments.size(),
loadedExperiments.size());
Assert.assertEquals(new HashSet<>(expectedExperiments), new
HashSet<>(loadedExperiments));