From c6ed526cee8a9e1c15fdf3be6c4fc9b1dbdb9ab7 Mon Sep 17 00:00:00 2001 From: NicolasHuertas Date: Sun, 8 Sep 2024 20:14:47 -0500 Subject: [PATCH 01/11] Added managed cyclical dependency example --- example.iml | 12 ++++++ java/com/engflow/cycleexample/class_a/BUILD | 24 +++++++++++ .../engflow/cycleexample/class_a/ClassA.java | 25 +++++++++++ .../cycleexample/class_a/ClassATest.java | 42 +++++++++++++++++++ java/com/engflow/cycleexample/class_b/BUILD | 19 +++++++++ .../engflow/cycleexample/class_b/ClassB.java | 18 ++++++++ .../cycleexample/class_b/ClassBTest.java | 35 ++++++++++++++++ java/com/engflow/cycleexample/class_c/BUILD | 20 +++++++++ .../engflow/cycleexample/class_c/ClassC.java | 29 +++++++++++++ .../cycleexample/class_c/ClassCTest.java | 35 ++++++++++++++++ .../engflow/cycleexample/interface_a/BUILD | 5 +++ .../cycleexample/interface_a/InterfaceA.java | 5 +++ .../engflow/cycleexample/interface_b/BUILD | 5 +++ .../cycleexample/interface_b/InterfaceB.java | 5 +++ java/com/engflow/cycleexample/main/BUILD | 12 ++++++ java/com/engflow/cycleexample/main/Main.java | 18 ++++++++ 16 files changed, 309 insertions(+) create mode 100644 example.iml create mode 100644 java/com/engflow/cycleexample/class_a/BUILD create mode 100644 java/com/engflow/cycleexample/class_a/ClassA.java create mode 100644 java/com/engflow/cycleexample/class_a/ClassATest.java create mode 100644 java/com/engflow/cycleexample/class_b/BUILD create mode 100644 java/com/engflow/cycleexample/class_b/ClassB.java create mode 100644 java/com/engflow/cycleexample/class_b/ClassBTest.java create mode 100644 java/com/engflow/cycleexample/class_c/BUILD create mode 100644 java/com/engflow/cycleexample/class_c/ClassC.java create mode 100644 java/com/engflow/cycleexample/class_c/ClassCTest.java create mode 100644 java/com/engflow/cycleexample/interface_a/BUILD create mode 100644 java/com/engflow/cycleexample/interface_a/InterfaceA.java create mode 100644 java/com/engflow/cycleexample/interface_b/BUILD create mode 100644 java/com/engflow/cycleexample/interface_b/InterfaceB.java create mode 100644 java/com/engflow/cycleexample/main/BUILD create mode 100644 java/com/engflow/cycleexample/main/Main.java diff --git a/example.iml b/example.iml new file mode 100644 index 00000000..a16bbfef --- /dev/null +++ b/example.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/java/com/engflow/cycleexample/class_a/BUILD b/java/com/engflow/cycleexample/class_a/BUILD new file mode 100644 index 00000000..0fb390a8 --- /dev/null +++ b/java/com/engflow/cycleexample/class_a/BUILD @@ -0,0 +1,24 @@ +package(default_visibility = ["//visibility:public"]) + +java_library( + name = "class_a", + srcs = ["ClassA.java"], + deps = [ + "//java/com/engflow/cycleexample/class_b", + "//java/com/engflow/cycleexample/interface_a", + ], +) + +java_test( + name = "class_a_test", + srcs = ["ClassATest.java"], + test_class = "cycleexample", + + + deps = [ + ":class_a", + "//java/com/engflow/cycleexample/class_b:class_b", + "//java/com/engflow/cycleexample/class_c:class_c", + "//java/com/engflow/cycleexample/interface_a:interface_a", + ], +) \ No newline at end of file diff --git a/java/com/engflow/cycleexample/class_a/ClassA.java b/java/com/engflow/cycleexample/class_a/ClassA.java new file mode 100644 index 00000000..0691e0f4 --- /dev/null +++ b/java/com/engflow/cycleexample/class_a/ClassA.java @@ -0,0 +1,25 @@ +package com.engflow.cycleexample.class_a; + +import com.engflow.cycleexample.class_b.ClassB; +import com.engflow.cycleexample.interface_a.InterfaceA; + +public class ClassA implements InterfaceA { + private static final int MAX_CALLS = 10; + private int callCount = 0; + private ClassB classB; + + public ClassA(ClassB classB) { + this.classB = classB; + } + + @Override + public void methodA() { + if (callCount >= MAX_CALLS) { + System.out.println("ClassA.methodA() reached max calls"); + return; + } + System.out.println("ClassA.methodA()"); + callCount++; + classB.methodB(); + } +} diff --git a/java/com/engflow/cycleexample/class_a/ClassATest.java b/java/com/engflow/cycleexample/class_a/ClassATest.java new file mode 100644 index 00000000..ab76e9d8 --- /dev/null +++ b/java/com/engflow/cycleexample/class_a/ClassATest.java @@ -0,0 +1,42 @@ +package com.engflow.cycleexample.class_a; + +import com.engflow.cycleexample.class_b.ClassB; +import com.engflow.cycleexample.class_c.ClassC; +import org.junit.Test; +import static org.junit.Assert.assertTrue; + +public class ClassATest { + private static class TestClassB extends ClassB { + boolean methodBCalled = false; + + public TestClassB(ClassC classC) { + super(classC); + } + + @Override + public void methodB() { + methodBCalled = true; + } + } + + @Test + public void testMethodA() { + // Create an instance of ClassA + ClassA classA = new ClassA(null); + + // Create a ClassC instance with the ClassA object + ClassC classC = new ClassC(classA); + + // Create a TestClassB instance with the ClassC object + TestClassB testClassB = new TestClassB(classC); + + // Create a new ClassA instance with the TestClassB object + classA = new ClassA(testClassB); + + // Call methodA on classA + classA.methodA(); + + // Verify that methodB on the TestClassB was called + assertTrue(testClassB.methodBCalled); + } +} \ No newline at end of file diff --git a/java/com/engflow/cycleexample/class_b/BUILD b/java/com/engflow/cycleexample/class_b/BUILD new file mode 100644 index 00000000..a325fc08 --- /dev/null +++ b/java/com/engflow/cycleexample/class_b/BUILD @@ -0,0 +1,19 @@ +package(default_visibility = ["//visibility:public"]) + +java_library( + name = "class_b", + srcs = ["ClassB.java"], + deps = [ + "//java/com/engflow/cycleexample/class_c", + "//java/com/engflow/cycleexample/interface_b", + ], +) + +java_test( + name = "class_b_test", + srcs = ["ClassBTest.java"], + test_class = "cycleexample", + deps = [":class_b", + "//java/com/engflow/cycleexample/class_c:class_c", + "//java/com/engflow/cycleexample/interface_b:interface_b"], +) \ No newline at end of file diff --git a/java/com/engflow/cycleexample/class_b/ClassB.java b/java/com/engflow/cycleexample/class_b/ClassB.java new file mode 100644 index 00000000..294aa88f --- /dev/null +++ b/java/com/engflow/cycleexample/class_b/ClassB.java @@ -0,0 +1,18 @@ +package com.engflow.cycleexample.class_b; + +import com.engflow.cycleexample.class_c.ClassC; +import com.engflow.cycleexample.interface_b.InterfaceB; + +public class ClassB implements InterfaceB { + private ClassC classC; + + public ClassB(ClassC classC) { + this.classC = classC; + } + + @Override + public void methodB() { + System.out.println("ClassB.methodB()"); + classC.methodA(); + } +} diff --git a/java/com/engflow/cycleexample/class_b/ClassBTest.java b/java/com/engflow/cycleexample/class_b/ClassBTest.java new file mode 100644 index 00000000..5bfcc3ae --- /dev/null +++ b/java/com/engflow/cycleexample/class_b/ClassBTest.java @@ -0,0 +1,35 @@ +package com.engflow.cycleexample.class_b; + +import com.engflow.cycleexample.class_c.ClassC; +import org.junit.Test; +import static org.junit.Assert.assertTrue; + +public class ClassBTest { + private static class TestClassC extends ClassC { + boolean methodACalled = false; + + public TestClassC() { + super(null); + } + + @Override + public void methodA() { + methodACalled = true; + } + } + + @Test + public void testMethodB() { + // Create a TestClassC instance + TestClassC testClassC = new TestClassC(); + + // Create an instance of ClassB with the TestClassC object + ClassB classB = new ClassB(testClassC); + + // Call methodB on classB + classB.methodB(); + + // Verify that methodA on the TestClassC was called + assertTrue(testClassC.methodACalled); + } +} \ No newline at end of file diff --git a/java/com/engflow/cycleexample/class_c/BUILD b/java/com/engflow/cycleexample/class_c/BUILD new file mode 100644 index 00000000..a793038c --- /dev/null +++ b/java/com/engflow/cycleexample/class_c/BUILD @@ -0,0 +1,20 @@ +package(default_visibility = ["//visibility:public"]) + +java_library( + name = "class_c", + srcs = ["ClassC.java"], + visibility = ["//visibility:public"], + deps = [ + "//java/com/engflow/cycleexample/interface_a", + ], +) + +java_test( + name = "class_c_test", + srcs = ["ClassCTest.java"], + test_class = "cycleexample", + deps = [ + ":class_c", + "//java/com/engflow/cycleexample/class_a:class_a", + ], +) \ No newline at end of file diff --git a/java/com/engflow/cycleexample/class_c/ClassC.java b/java/com/engflow/cycleexample/class_c/ClassC.java new file mode 100644 index 00000000..6a94d07b --- /dev/null +++ b/java/com/engflow/cycleexample/class_c/ClassC.java @@ -0,0 +1,29 @@ +package com.engflow.cycleexample.class_c; + +import com.engflow.cycleexample.interface_a.InterfaceA; + +public class ClassC implements InterfaceA { + private InterfaceA classA; + + public ClassC(InterfaceA classA) { + this.classA = classA; + } + + @Override + public void methodA() { + System.out.println("ClassC.methodA()"); + if (classA != null) { + classA.methodA(); + } else { + System.out.println("classA is null"); + } + } + + public void setClassA(InterfaceA classA) { + this.classA = classA; + } + + public void methodC() { + System.out.println("ClassC.methodC()"); + } +} \ No newline at end of file diff --git a/java/com/engflow/cycleexample/class_c/ClassCTest.java b/java/com/engflow/cycleexample/class_c/ClassCTest.java new file mode 100644 index 00000000..f07675ae --- /dev/null +++ b/java/com/engflow/cycleexample/class_c/ClassCTest.java @@ -0,0 +1,35 @@ +package com.engflow.cycleexample.class_c; + +import com.engflow.cycleexample.class_a.ClassA; +import org.junit.Test; +import static org.junit.Assert.assertTrue; + +public class ClassCTest { + private static class TestClassA extends ClassA { + boolean methodACalled = false; + + public TestClassA() { + super(null); + } + + @Override + public void methodA() { + methodACalled = true; + } + } + + @Test + public void testMethodA() { + // Create a TestClassA instance + TestClassA testClassA = new TestClassA(); + + // Create an instance of ClassC with the TestClassA object + ClassC classC = new ClassC(testClassA); + + // Call methodA on classC + classC.methodA(); + + // Verify that methodA on the TestClassA was called + assertTrue(testClassA.methodACalled); + } +} \ No newline at end of file diff --git a/java/com/engflow/cycleexample/interface_a/BUILD b/java/com/engflow/cycleexample/interface_a/BUILD new file mode 100644 index 00000000..5f6a706b --- /dev/null +++ b/java/com/engflow/cycleexample/interface_a/BUILD @@ -0,0 +1,5 @@ +java_library( + name = "interface_a", + srcs = ["InterfaceA.java"], + visibility = ["//visibility:public"], +) \ No newline at end of file diff --git a/java/com/engflow/cycleexample/interface_a/InterfaceA.java b/java/com/engflow/cycleexample/interface_a/InterfaceA.java new file mode 100644 index 00000000..59c18f0c --- /dev/null +++ b/java/com/engflow/cycleexample/interface_a/InterfaceA.java @@ -0,0 +1,5 @@ +package com.engflow.cycleexample.interface_a; + +public interface InterfaceA { + void methodA(); +} diff --git a/java/com/engflow/cycleexample/interface_b/BUILD b/java/com/engflow/cycleexample/interface_b/BUILD new file mode 100644 index 00000000..fc1c1352 --- /dev/null +++ b/java/com/engflow/cycleexample/interface_b/BUILD @@ -0,0 +1,5 @@ +java_library( + name = "interface_b", + srcs = ["InterfaceB.java"], + visibility = ["//visibility:public"], +) \ No newline at end of file diff --git a/java/com/engflow/cycleexample/interface_b/InterfaceB.java b/java/com/engflow/cycleexample/interface_b/InterfaceB.java new file mode 100644 index 00000000..37e8f01b --- /dev/null +++ b/java/com/engflow/cycleexample/interface_b/InterfaceB.java @@ -0,0 +1,5 @@ +package com.engflow.cycleexample.interface_b; + +public interface InterfaceB { + void methodB(); +} \ No newline at end of file diff --git a/java/com/engflow/cycleexample/main/BUILD b/java/com/engflow/cycleexample/main/BUILD new file mode 100644 index 00000000..6bac2da7 --- /dev/null +++ b/java/com/engflow/cycleexample/main/BUILD @@ -0,0 +1,12 @@ +load("@rules_java//java:defs.bzl", "java_binary") + +java_binary( + name = "main", + srcs = ["Main.java"], + deps = [ + "//java/com/engflow/cycleexample/class_a", + "//java/com/engflow/cycleexample/class_b", + "//java/com/engflow/cycleexample/class_c", + ], + main_class = "cycleexample", +) \ No newline at end of file diff --git a/java/com/engflow/cycleexample/main/Main.java b/java/com/engflow/cycleexample/main/Main.java new file mode 100644 index 00000000..36155d1b --- /dev/null +++ b/java/com/engflow/cycleexample/main/Main.java @@ -0,0 +1,18 @@ +package com.engflow.cycleexample.main; + +import com.engflow.cycleexample.class_a.ClassA; +import com.engflow.cycleexample.class_b.ClassB; +import com.engflow.cycleexample.class_c.ClassC; + +public class Main { + public static void main(String[] args) { + ClassC classC = new ClassC(null); + ClassB classB = new ClassB(classC); + ClassA classA = new ClassA(classB); + + // Properly initialize classC with classA + classC.setClassA(classA); + + classA.methodA(); + } +} \ No newline at end of file From f8ee4ff77c68afc260b49c00321733623d194fcd Mon Sep 17 00:00:00 2001 From: NicolasHuertas Date: Sat, 14 Sep 2024 11:20:28 -0500 Subject: [PATCH 02/11] Refractored folder and fixed run error --- java/com/engflow/cycleexample/class_a/BUILD | 24 ------------------- java/com/engflow/cycleexample/class_b/BUILD | 19 --------------- .../cycleexample/interface_a/InterfaceA.java | 5 ---- .../cycleexample/interface_b/InterfaceB.java | 5 ---- java/com/engflow/cycleexample/main/BUILD | 12 ---------- .../internship/cycleexample/class_a/BUILD | 22 +++++++++++++++++ .../cycleexample/class_a/ClassA.java | 6 ++--- .../cycleexample/class_a/ClassATest.java | 6 ++--- .../internship/cycleexample/class_b/BUILD | 21 ++++++++++++++++ .../cycleexample/class_b/ClassB.java | 6 ++--- .../cycleexample/class_b/ClassBTest.java | 4 ++-- .../cycleexample/class_c/BUILD | 4 ++-- .../cycleexample/class_c/ClassC.java | 4 ++-- .../cycleexample/class_c/ClassCTest.java | 4 ++-- .../cycleexample/interface_a/BUILD | 0 .../cycleexample/interface_a/InterfaceA.java | 5 ++++ .../cycleexample/interface_b/BUILD | 0 .../cycleexample/interface_b/InterfaceB.java | 5 ++++ .../internship/cycleexample/main/BUILD | 12 ++++++++++ .../cycleexample/main/Main.java | 8 +++---- 20 files changed, 86 insertions(+), 86 deletions(-) delete mode 100644 java/com/engflow/cycleexample/class_a/BUILD delete mode 100644 java/com/engflow/cycleexample/class_b/BUILD delete mode 100644 java/com/engflow/cycleexample/interface_a/InterfaceA.java delete mode 100644 java/com/engflow/cycleexample/interface_b/InterfaceB.java delete mode 100644 java/com/engflow/cycleexample/main/BUILD create mode 100644 java/com/engflow/internship/cycleexample/class_a/BUILD rename java/com/engflow/{ => internship}/cycleexample/class_a/ClassA.java (73%) rename java/com/engflow/{ => internship}/cycleexample/class_a/ClassATest.java (85%) create mode 100644 java/com/engflow/internship/cycleexample/class_b/BUILD rename java/com/engflow/{ => internship}/cycleexample/class_b/ClassB.java (60%) rename java/com/engflow/{ => internship}/cycleexample/class_b/ClassBTest.java (87%) rename java/com/engflow/{ => internship}/cycleexample/class_c/BUILD (70%) rename java/com/engflow/{ => internship}/cycleexample/class_c/ClassC.java (82%) rename java/com/engflow/{ => internship}/cycleexample/class_c/ClassCTest.java (87%) rename java/com/engflow/{ => internship}/cycleexample/interface_a/BUILD (100%) create mode 100644 java/com/engflow/internship/cycleexample/interface_a/InterfaceA.java rename java/com/engflow/{ => internship}/cycleexample/interface_b/BUILD (100%) create mode 100644 java/com/engflow/internship/cycleexample/interface_b/InterfaceB.java create mode 100644 java/com/engflow/internship/cycleexample/main/BUILD rename java/com/engflow/{ => internship}/cycleexample/main/Main.java (58%) diff --git a/java/com/engflow/cycleexample/class_a/BUILD b/java/com/engflow/cycleexample/class_a/BUILD deleted file mode 100644 index 0fb390a8..00000000 --- a/java/com/engflow/cycleexample/class_a/BUILD +++ /dev/null @@ -1,24 +0,0 @@ -package(default_visibility = ["//visibility:public"]) - -java_library( - name = "class_a", - srcs = ["ClassA.java"], - deps = [ - "//java/com/engflow/cycleexample/class_b", - "//java/com/engflow/cycleexample/interface_a", - ], -) - -java_test( - name = "class_a_test", - srcs = ["ClassATest.java"], - test_class = "cycleexample", - - - deps = [ - ":class_a", - "//java/com/engflow/cycleexample/class_b:class_b", - "//java/com/engflow/cycleexample/class_c:class_c", - "//java/com/engflow/cycleexample/interface_a:interface_a", - ], -) \ No newline at end of file diff --git a/java/com/engflow/cycleexample/class_b/BUILD b/java/com/engflow/cycleexample/class_b/BUILD deleted file mode 100644 index a325fc08..00000000 --- a/java/com/engflow/cycleexample/class_b/BUILD +++ /dev/null @@ -1,19 +0,0 @@ -package(default_visibility = ["//visibility:public"]) - -java_library( - name = "class_b", - srcs = ["ClassB.java"], - deps = [ - "//java/com/engflow/cycleexample/class_c", - "//java/com/engflow/cycleexample/interface_b", - ], -) - -java_test( - name = "class_b_test", - srcs = ["ClassBTest.java"], - test_class = "cycleexample", - deps = [":class_b", - "//java/com/engflow/cycleexample/class_c:class_c", - "//java/com/engflow/cycleexample/interface_b:interface_b"], -) \ No newline at end of file diff --git a/java/com/engflow/cycleexample/interface_a/InterfaceA.java b/java/com/engflow/cycleexample/interface_a/InterfaceA.java deleted file mode 100644 index 59c18f0c..00000000 --- a/java/com/engflow/cycleexample/interface_a/InterfaceA.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.engflow.cycleexample.interface_a; - -public interface InterfaceA { - void methodA(); -} diff --git a/java/com/engflow/cycleexample/interface_b/InterfaceB.java b/java/com/engflow/cycleexample/interface_b/InterfaceB.java deleted file mode 100644 index 37e8f01b..00000000 --- a/java/com/engflow/cycleexample/interface_b/InterfaceB.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.engflow.cycleexample.interface_b; - -public interface InterfaceB { - void methodB(); -} \ No newline at end of file diff --git a/java/com/engflow/cycleexample/main/BUILD b/java/com/engflow/cycleexample/main/BUILD deleted file mode 100644 index 6bac2da7..00000000 --- a/java/com/engflow/cycleexample/main/BUILD +++ /dev/null @@ -1,12 +0,0 @@ -load("@rules_java//java:defs.bzl", "java_binary") - -java_binary( - name = "main", - srcs = ["Main.java"], - deps = [ - "//java/com/engflow/cycleexample/class_a", - "//java/com/engflow/cycleexample/class_b", - "//java/com/engflow/cycleexample/class_c", - ], - main_class = "cycleexample", -) \ No newline at end of file diff --git a/java/com/engflow/internship/cycleexample/class_a/BUILD b/java/com/engflow/internship/cycleexample/class_a/BUILD new file mode 100644 index 00000000..eebfa559 --- /dev/null +++ b/java/com/engflow/internship/cycleexample/class_a/BUILD @@ -0,0 +1,22 @@ +package(default_visibility = ["//visibility:public"]) + +java_library( + name = "class_a", + srcs = ["ClassA.java"], + deps = [ + "//java/com/engflow/internship/cycleexample/class_b", + "//java/com/engflow/internship/cycleexample/interface_a", + ], +) + +java_test( + name = "class_a_test", + srcs = ["ClassATest.java"], + test_class = "cycleexample", + deps = [ + ":class_a", + "//java/com/engflow/internship/cycleexample/class_b:class_b", + "//java/com/engflow/internship/cycleexample/class_c:class_c", + "//java/com/engflow/internship/cycleexample/interface_a:interface_a", + ], +) \ No newline at end of file diff --git a/java/com/engflow/cycleexample/class_a/ClassA.java b/java/com/engflow/internship/cycleexample/class_a/ClassA.java similarity index 73% rename from java/com/engflow/cycleexample/class_a/ClassA.java rename to java/com/engflow/internship/cycleexample/class_a/ClassA.java index 0691e0f4..443c8ed4 100644 --- a/java/com/engflow/cycleexample/class_a/ClassA.java +++ b/java/com/engflow/internship/cycleexample/class_a/ClassA.java @@ -1,7 +1,7 @@ -package com.engflow.cycleexample.class_a; +package com.engflow.internship.cycleexample.class_a; -import com.engflow.cycleexample.class_b.ClassB; -import com.engflow.cycleexample.interface_a.InterfaceA; +import com.engflow.internship.cycleexample.class_b.ClassB; +import com.engflow.internship.cycleexample.interface_a.InterfaceA; public class ClassA implements InterfaceA { private static final int MAX_CALLS = 10; diff --git a/java/com/engflow/cycleexample/class_a/ClassATest.java b/java/com/engflow/internship/cycleexample/class_a/ClassATest.java similarity index 85% rename from java/com/engflow/cycleexample/class_a/ClassATest.java rename to java/com/engflow/internship/cycleexample/class_a/ClassATest.java index ab76e9d8..a29334c1 100644 --- a/java/com/engflow/cycleexample/class_a/ClassATest.java +++ b/java/com/engflow/internship/cycleexample/class_a/ClassATest.java @@ -1,7 +1,7 @@ -package com.engflow.cycleexample.class_a; +package com.engflow.internship.cycleexample.class_a; -import com.engflow.cycleexample.class_b.ClassB; -import com.engflow.cycleexample.class_c.ClassC; +import com.engflow.internship.cycleexample.class_b.ClassB; +import com.engflow.internship.cycleexample.class_c.ClassC; import org.junit.Test; import static org.junit.Assert.assertTrue; diff --git a/java/com/engflow/internship/cycleexample/class_b/BUILD b/java/com/engflow/internship/cycleexample/class_b/BUILD new file mode 100644 index 00000000..e233fd77 --- /dev/null +++ b/java/com/engflow/internship/cycleexample/class_b/BUILD @@ -0,0 +1,21 @@ +package(default_visibility = ["//visibility:public"]) + +java_library( + name = "class_b", + srcs = ["ClassB.java"], + deps = [ + "//java/com/engflow/internship/cycleexample/class_c", + "//java/com/engflow/internship/cycleexample/interface_b", + ], +) + +java_test( + name = "class_b_test", + srcs = ["ClassBTest.java"], + test_class = "cycleexample", + deps = [ + ":class_b", + "//java/com/engflow/internship/cycleexample/class_c:class_c", + "//java/com/engflow/internship/cycleexample/interface_b:interface_b", + ], +) \ No newline at end of file diff --git a/java/com/engflow/cycleexample/class_b/ClassB.java b/java/com/engflow/internship/cycleexample/class_b/ClassB.java similarity index 60% rename from java/com/engflow/cycleexample/class_b/ClassB.java rename to java/com/engflow/internship/cycleexample/class_b/ClassB.java index 294aa88f..e3dbc66d 100644 --- a/java/com/engflow/cycleexample/class_b/ClassB.java +++ b/java/com/engflow/internship/cycleexample/class_b/ClassB.java @@ -1,7 +1,7 @@ -package com.engflow.cycleexample.class_b; +package com.engflow.internship.cycleexample.class_b; -import com.engflow.cycleexample.class_c.ClassC; -import com.engflow.cycleexample.interface_b.InterfaceB; +import com.engflow.internship.cycleexample.class_c.ClassC; +import com.engflow.internship.cycleexample.interface_b.InterfaceB; public class ClassB implements InterfaceB { private ClassC classC; diff --git a/java/com/engflow/cycleexample/class_b/ClassBTest.java b/java/com/engflow/internship/cycleexample/class_b/ClassBTest.java similarity index 87% rename from java/com/engflow/cycleexample/class_b/ClassBTest.java rename to java/com/engflow/internship/cycleexample/class_b/ClassBTest.java index 5bfcc3ae..dc9a01f6 100644 --- a/java/com/engflow/cycleexample/class_b/ClassBTest.java +++ b/java/com/engflow/internship/cycleexample/class_b/ClassBTest.java @@ -1,6 +1,6 @@ -package com.engflow.cycleexample.class_b; +package com.engflow.internship.cycleexample.class_b; -import com.engflow.cycleexample.class_c.ClassC; +import com.engflow.internship.cycleexample.class_c.ClassC; import org.junit.Test; import static org.junit.Assert.assertTrue; diff --git a/java/com/engflow/cycleexample/class_c/BUILD b/java/com/engflow/internship/cycleexample/class_c/BUILD similarity index 70% rename from java/com/engflow/cycleexample/class_c/BUILD rename to java/com/engflow/internship/cycleexample/class_c/BUILD index a793038c..319b034c 100644 --- a/java/com/engflow/cycleexample/class_c/BUILD +++ b/java/com/engflow/internship/cycleexample/class_c/BUILD @@ -5,7 +5,7 @@ java_library( srcs = ["ClassC.java"], visibility = ["//visibility:public"], deps = [ - "//java/com/engflow/cycleexample/interface_a", + "//java/com/engflow/internship/cycleexample/interface_a", ], ) @@ -15,6 +15,6 @@ java_test( test_class = "cycleexample", deps = [ ":class_c", - "//java/com/engflow/cycleexample/class_a:class_a", + "//java/com/engflow/internship/cycleexample/class_a:class_a", ], ) \ No newline at end of file diff --git a/java/com/engflow/cycleexample/class_c/ClassC.java b/java/com/engflow/internship/cycleexample/class_c/ClassC.java similarity index 82% rename from java/com/engflow/cycleexample/class_c/ClassC.java rename to java/com/engflow/internship/cycleexample/class_c/ClassC.java index 6a94d07b..f61d324f 100644 --- a/java/com/engflow/cycleexample/class_c/ClassC.java +++ b/java/com/engflow/internship/cycleexample/class_c/ClassC.java @@ -1,6 +1,6 @@ -package com.engflow.cycleexample.class_c; +package com.engflow.internship.cycleexample.class_c; -import com.engflow.cycleexample.interface_a.InterfaceA; +import com.engflow.internship.cycleexample.interface_a.InterfaceA; public class ClassC implements InterfaceA { private InterfaceA classA; diff --git a/java/com/engflow/cycleexample/class_c/ClassCTest.java b/java/com/engflow/internship/cycleexample/class_c/ClassCTest.java similarity index 87% rename from java/com/engflow/cycleexample/class_c/ClassCTest.java rename to java/com/engflow/internship/cycleexample/class_c/ClassCTest.java index f07675ae..7482cc9d 100644 --- a/java/com/engflow/cycleexample/class_c/ClassCTest.java +++ b/java/com/engflow/internship/cycleexample/class_c/ClassCTest.java @@ -1,6 +1,6 @@ -package com.engflow.cycleexample.class_c; +package com.engflow.internship.cycleexample.class_c; -import com.engflow.cycleexample.class_a.ClassA; +import com.engflow.internship.cycleexample.class_a.ClassA; import org.junit.Test; import static org.junit.Assert.assertTrue; diff --git a/java/com/engflow/cycleexample/interface_a/BUILD b/java/com/engflow/internship/cycleexample/interface_a/BUILD similarity index 100% rename from java/com/engflow/cycleexample/interface_a/BUILD rename to java/com/engflow/internship/cycleexample/interface_a/BUILD diff --git a/java/com/engflow/internship/cycleexample/interface_a/InterfaceA.java b/java/com/engflow/internship/cycleexample/interface_a/InterfaceA.java new file mode 100644 index 00000000..ff76a8db --- /dev/null +++ b/java/com/engflow/internship/cycleexample/interface_a/InterfaceA.java @@ -0,0 +1,5 @@ +package com.engflow.internship.cycleexample.interface_a; + +public interface InterfaceA { + void methodA(); +} diff --git a/java/com/engflow/cycleexample/interface_b/BUILD b/java/com/engflow/internship/cycleexample/interface_b/BUILD similarity index 100% rename from java/com/engflow/cycleexample/interface_b/BUILD rename to java/com/engflow/internship/cycleexample/interface_b/BUILD diff --git a/java/com/engflow/internship/cycleexample/interface_b/InterfaceB.java b/java/com/engflow/internship/cycleexample/interface_b/InterfaceB.java new file mode 100644 index 00000000..af637e71 --- /dev/null +++ b/java/com/engflow/internship/cycleexample/interface_b/InterfaceB.java @@ -0,0 +1,5 @@ +package com.engflow.internship.cycleexample.interface_b; + +public interface InterfaceB { + void methodB(); +} \ No newline at end of file diff --git a/java/com/engflow/internship/cycleexample/main/BUILD b/java/com/engflow/internship/cycleexample/main/BUILD new file mode 100644 index 00000000..525fb4c6 --- /dev/null +++ b/java/com/engflow/internship/cycleexample/main/BUILD @@ -0,0 +1,12 @@ +load("@rules_java//java:defs.bzl", "java_binary") + +java_binary( + name = "main", + srcs = ["Main.java"], + deps = [ + "//java/com/engflow/internship/cycleexample/class_a", + "//java/com/engflow/internship/cycleexample/class_b", + "//java/com/engflow/internship/cycleexample/class_c", + ], + main_class = "com.engflow.internship.cycleexample.main.Main", +) \ No newline at end of file diff --git a/java/com/engflow/cycleexample/main/Main.java b/java/com/engflow/internship/cycleexample/main/Main.java similarity index 58% rename from java/com/engflow/cycleexample/main/Main.java rename to java/com/engflow/internship/cycleexample/main/Main.java index 36155d1b..9c65885e 100644 --- a/java/com/engflow/cycleexample/main/Main.java +++ b/java/com/engflow/internship/cycleexample/main/Main.java @@ -1,8 +1,8 @@ -package com.engflow.cycleexample.main; +package com.engflow.internship.cycleexample.main; -import com.engflow.cycleexample.class_a.ClassA; -import com.engflow.cycleexample.class_b.ClassB; -import com.engflow.cycleexample.class_c.ClassC; +import com.engflow.internship.cycleexample.class_a.ClassA; +import com.engflow.internship.cycleexample.class_b.ClassB; +import com.engflow.internship.cycleexample.class_c.ClassC; public class Main { public static void main(String[] args) { From 13f69620c4c77e7329ced5dd03b9bebcdb08c6d9 Mon Sep 17 00:00:00 2001 From: Huertas Cadavid Nicolas Fernando <98675931+NicolasHuertas@users.noreply.github.com> Date: Sun, 15 Sep 2024 13:12:46 -0500 Subject: [PATCH 03/11] Create README.md --- java/com/engflow/internship/README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 java/com/engflow/internship/README.md diff --git a/java/com/engflow/internship/README.md b/java/com/engflow/internship/README.md new file mode 100644 index 00000000..c1c7706b --- /dev/null +++ b/java/com/engflow/internship/README.md @@ -0,0 +1,13 @@ +# Example Projects for Performance Testing + +## Overview + +Welcome to the `internship` folder of the EngFlow examples repository. This folder contains a set of example projects designed to evaluate and benchmark the performance of EngFlow's remote execution and caching services. These projects aim to provide a diverse range of test cases with varying input sizes, numbers of inputs, and execution times. The goal is to generate performance data that can help in understanding how different factors affect the performance of remote build optimization services. + +## Purpose + +The primary objectives of these example projects are to: + +1. **Generate Performance Data**: Create examples with varying complexity to test and gather performance data for EngFlow’s remote caching and execution services. +2. **Benchmark Analysis**: Compare the performance of local versus remote execution and caching to evaluate the efficiency and effectiveness of the service. +3. **Support Automation Development**: Contribute to the development of automation algorithms for resource assignment by providing valuable data on how the size and nature of the builds impact performance. From 4fcc28b59f221da30c0c62255bfb772f23468eee Mon Sep 17 00:00:00 2001 From: NicolasHuertas Date: Mon, 16 Sep 2024 17:59:23 -0500 Subject: [PATCH 04/11] Program now reads through an input file --- .../engflow/internship/cycleexample/README.md | 39 +++++++++++++++++++ .../internship/cycleexample/class_a/BUILD | 2 +- .../cycleexample/class_a/ClassA.java | 24 +++++++----- .../cycleexample/class_a/ClassATest.java | 18 ++++----- .../internship/cycleexample/class_b/BUILD | 2 +- .../cycleexample/class_b/ClassB.java | 21 ++++++++-- .../cycleexample/class_b/ClassBTest.java | 4 +- .../internship/cycleexample/class_c/BUILD | 2 +- .../cycleexample/class_c/ClassC.java | 29 +++++++++----- .../cycleexample/class_c/ClassCTest.java | 4 +- .../internship/cycleexample/input/BUILD | 5 +++ .../internship/cycleexample/input/input.txt | 1 + .../cycleexample/interface_a/InterfaceA.java | 2 +- .../cycleexample/interface_b/InterfaceB.java | 2 +- .../internship/cycleexample/main/BUILD | 3 ++ .../internship/cycleexample/main/Main.java | 23 ++++++++++- 16 files changed, 139 insertions(+), 42 deletions(-) create mode 100644 java/com/engflow/internship/cycleexample/README.md create mode 100644 java/com/engflow/internship/cycleexample/input/BUILD create mode 100644 java/com/engflow/internship/cycleexample/input/input.txt diff --git a/java/com/engflow/internship/cycleexample/README.md b/java/com/engflow/internship/cycleexample/README.md new file mode 100644 index 00000000..ec1d02d6 --- /dev/null +++ b/java/com/engflow/internship/cycleexample/README.md @@ -0,0 +1,39 @@ +# Cyclical Dependency Example + +## Overview + +This project is designed to evaluate and benchmark the performance of EngFlow's remote execution and caching services. It specifically focuses on testing scenarios involving cyclical-like structures in the dependency graph, which are handled through interfaces and constructor injection. + +## Purpose + +The primary objectives of this project are to: + +1. **Generate Performance Data**: Create examples with cyclical-like dependencies to test and gather performance data for EngFlow’s remote caching and execution services. +2. **Benchmark Analysis**: Compare the performance of local versus remote execution and caching to evaluate the efficiency and effectiveness of the service. +3. **Support Automation Development**: Contribute to the development of automation algorithms for resource assignment by providing valuable data on how cyclical dependencies impact performance. + +## Project Structure + +The project is organized into several packages, each representing different components of the cyclical dependency example: + +- `class_a`: Contains `ClassA` which depends on `ClassB` through an interface. +- `class_b`: Contains `ClassB` which implements `InterfaceB` and depends on `ClassC`. +- `class_c`: Contains `ClassC` which implements `InterfaceA` and can be initialized with a reference to `ClassA`. +- `interface_a`: Defines the interface `InterfaceA` implemented by `ClassA` and `ClassC`. +- `interface_b`: Defines the interface `InterfaceB` implemented by `ClassB`. +- `main`: Contains the `Main` class which processes the input file. +- `input`: Contains the input text file used by the `Main` class. + +## How the Program Works + +The program takes a text input file and recursively prints each word with each class (`ClassA` prints a word, then `ClassB`, and so on) until the string is empty. The input file should be specified in the `data` attribute of the `java_binary` rule in the `BUILD` file. + +Here is an example of how the `Main` class processes the input file: + + +## How to Run Tests + +To run the tests and gather performance data, use the following Bazel command: + +```sh +bazel test //java/com/engflow/internship/cycleexample/class_a:class_a_test \ No newline at end of file diff --git a/java/com/engflow/internship/cycleexample/class_a/BUILD b/java/com/engflow/internship/cycleexample/class_a/BUILD index eebfa559..94248ce9 100644 --- a/java/com/engflow/internship/cycleexample/class_a/BUILD +++ b/java/com/engflow/internship/cycleexample/class_a/BUILD @@ -12,7 +12,7 @@ java_library( java_test( name = "class_a_test", srcs = ["ClassATest.java"], - test_class = "cycleexample", + test_class = "com.engflow.internship.cycleexample.class_a.ClassATest", deps = [ ":class_a", "//java/com/engflow/internship/cycleexample/class_b:class_b", diff --git a/java/com/engflow/internship/cycleexample/class_a/ClassA.java b/java/com/engflow/internship/cycleexample/class_a/ClassA.java index 443c8ed4..f5f4d005 100644 --- a/java/com/engflow/internship/cycleexample/class_a/ClassA.java +++ b/java/com/engflow/internship/cycleexample/class_a/ClassA.java @@ -4,8 +4,6 @@ import com.engflow.internship.cycleexample.interface_a.InterfaceA; public class ClassA implements InterfaceA { - private static final int MAX_CALLS = 10; - private int callCount = 0; private ClassB classB; public ClassA(ClassB classB) { @@ -13,13 +11,21 @@ public ClassA(ClassB classB) { } @Override - public void methodA() { - if (callCount >= MAX_CALLS) { - System.out.println("ClassA.methodA() reached max calls"); + public void methodA(String input) { + // If the input is null or empty, return immediately + if (input == null || input.isEmpty()) { return; } - System.out.println("ClassA.methodA()"); - callCount++; - classB.methodB(); + + //Find the index of the first space character in the input string. + int spaceIndex = input.indexOf(' '); + //Extract the word from the beginning of the input string up to the space character. + String word = (spaceIndex == -1) ? input : input.substring(0, spaceIndex); + //Extract the remaining part of the input string after the space character. + String remaining = (spaceIndex == -1) ? "" : input.substring(spaceIndex + 1); + + //Print the word extracted from the input string. + System.out.println("ClassA: " + word); + classB.methodB(remaining); } -} +} \ No newline at end of file diff --git a/java/com/engflow/internship/cycleexample/class_a/ClassATest.java b/java/com/engflow/internship/cycleexample/class_a/ClassATest.java index a29334c1..6725a648 100644 --- a/java/com/engflow/internship/cycleexample/class_a/ClassATest.java +++ b/java/com/engflow/internship/cycleexample/class_a/ClassATest.java @@ -14,27 +14,27 @@ public TestClassB(ClassC classC) { } @Override - public void methodB() { + public void methodB(String input) { methodBCalled = true; } } @Test public void testMethodA() { - // Create an instance of ClassA - ClassA classA = new ClassA(null); - - // Create a ClassC instance with the ClassA object - ClassC classC = new ClassC(classA); + // Create a ClassC instance with a null ClassA object + ClassC classC = new ClassC(null); // Create a TestClassB instance with the ClassC object TestClassB testClassB = new TestClassB(classC); // Create a new ClassA instance with the TestClassB object - classA = new ClassA(testClassB); + ClassA classA = new ClassA(testClassB); + + // Properly initialize classC with classA + classC.setClassA(classA); - // Call methodA on classA - classA.methodA(); + // Call methodA on classA with a sample input + classA.methodA("sample input"); // Verify that methodB on the TestClassB was called assertTrue(testClassB.methodBCalled); diff --git a/java/com/engflow/internship/cycleexample/class_b/BUILD b/java/com/engflow/internship/cycleexample/class_b/BUILD index e233fd77..4c9b6eeb 100644 --- a/java/com/engflow/internship/cycleexample/class_b/BUILD +++ b/java/com/engflow/internship/cycleexample/class_b/BUILD @@ -12,7 +12,7 @@ java_library( java_test( name = "class_b_test", srcs = ["ClassBTest.java"], - test_class = "cycleexample", + test_class = "com.engflow.internship.cycleexample.class_b.ClassBTest", deps = [ ":class_b", "//java/com/engflow/internship/cycleexample/class_c:class_c", diff --git a/java/com/engflow/internship/cycleexample/class_b/ClassB.java b/java/com/engflow/internship/cycleexample/class_b/ClassB.java index e3dbc66d..605837d6 100644 --- a/java/com/engflow/internship/cycleexample/class_b/ClassB.java +++ b/java/com/engflow/internship/cycleexample/class_b/ClassB.java @@ -11,8 +11,21 @@ public ClassB(ClassC classC) { } @Override - public void methodB() { - System.out.println("ClassB.methodB()"); - classC.methodA(); + public void methodB(String input) { + // If the input is null or empty, return immediately + if (input == null || input.isEmpty()) { + return; + } + + //Find the index of the first space character in the input string. + int spaceIndex = input.indexOf(' '); + //Extract the word from the beginning of the input string up to the space character. + String word = (spaceIndex == -1) ? input : input.substring(0, spaceIndex); + //Extract the remaining part of the input string after the space character. + String remaining = (spaceIndex == -1) ? "" : input.substring(spaceIndex + 1); + + //Print the word extracted from the input string. + System.out.println("ClassB: " + word); + classC.methodA(remaining); } -} +} \ No newline at end of file diff --git a/java/com/engflow/internship/cycleexample/class_b/ClassBTest.java b/java/com/engflow/internship/cycleexample/class_b/ClassBTest.java index dc9a01f6..cacca271 100644 --- a/java/com/engflow/internship/cycleexample/class_b/ClassBTest.java +++ b/java/com/engflow/internship/cycleexample/class_b/ClassBTest.java @@ -13,7 +13,7 @@ public TestClassC() { } @Override - public void methodA() { + public void methodA(String input) { methodACalled = true; } } @@ -27,7 +27,7 @@ public void testMethodB() { ClassB classB = new ClassB(testClassC); // Call methodB on classB - classB.methodB(); + classB.methodB("Sample input"); // Verify that methodA on the TestClassC was called assertTrue(testClassC.methodACalled); diff --git a/java/com/engflow/internship/cycleexample/class_c/BUILD b/java/com/engflow/internship/cycleexample/class_c/BUILD index 319b034c..d9580687 100644 --- a/java/com/engflow/internship/cycleexample/class_c/BUILD +++ b/java/com/engflow/internship/cycleexample/class_c/BUILD @@ -12,7 +12,7 @@ java_library( java_test( name = "class_c_test", srcs = ["ClassCTest.java"], - test_class = "cycleexample", + test_class = "com.engflow.internship.cycleexample.class_c.ClassCTest", deps = [ ":class_c", "//java/com/engflow/internship/cycleexample/class_a:class_a", diff --git a/java/com/engflow/internship/cycleexample/class_c/ClassC.java b/java/com/engflow/internship/cycleexample/class_c/ClassC.java index f61d324f..12b6b0a9 100644 --- a/java/com/engflow/internship/cycleexample/class_c/ClassC.java +++ b/java/com/engflow/internship/cycleexample/class_c/ClassC.java @@ -10,20 +10,29 @@ public ClassC(InterfaceA classA) { } @Override - public void methodA() { - System.out.println("ClassC.methodA()"); - if (classA != null) { - classA.methodA(); - } else { - System.out.println("classA is null"); + public void methodA(String input) { + // If the input is null or empty, return immediately + if (input == null || input.isEmpty()) { + return; } + + // Find the index of the first space character in the input string. + int spaceIndex = input.indexOf(' '); + // Extract the word from the beginning of the input string up to the space character. + String word = (spaceIndex == -1) ? input : input.substring(0, spaceIndex); + // Extract the remaining part of the input string after the space character. + String remaining = (spaceIndex == -1) ? "" : input.substring(spaceIndex + 1); + + // Print the word extracted from the input string. + System.out.println("ClassC: " + word); + classA.methodA(remaining); } + /** + * Set the classA field of this class. + * @param classA + */ public void setClassA(InterfaceA classA) { this.classA = classA; } - - public void methodC() { - System.out.println("ClassC.methodC()"); - } } \ No newline at end of file diff --git a/java/com/engflow/internship/cycleexample/class_c/ClassCTest.java b/java/com/engflow/internship/cycleexample/class_c/ClassCTest.java index 7482cc9d..c9cf7086 100644 --- a/java/com/engflow/internship/cycleexample/class_c/ClassCTest.java +++ b/java/com/engflow/internship/cycleexample/class_c/ClassCTest.java @@ -13,7 +13,7 @@ public TestClassA() { } @Override - public void methodA() { + public void methodA(String input) { methodACalled = true; } } @@ -27,7 +27,7 @@ public void testMethodA() { ClassC classC = new ClassC(testClassA); // Call methodA on classC - classC.methodA(); + classC.methodA("sample input"); // Verify that methodA on the TestClassA was called assertTrue(testClassA.methodACalled); diff --git a/java/com/engflow/internship/cycleexample/input/BUILD b/java/com/engflow/internship/cycleexample/input/BUILD new file mode 100644 index 00000000..4b9e382f --- /dev/null +++ b/java/com/engflow/internship/cycleexample/input/BUILD @@ -0,0 +1,5 @@ +filegroup( + name = "input", + srcs = glob(["*.txt"]), + visibility = ["//visibility:public"], +) \ No newline at end of file diff --git a/java/com/engflow/internship/cycleexample/input/input.txt b/java/com/engflow/internship/cycleexample/input/input.txt new file mode 100644 index 00000000..7e0f7d52 --- /dev/null +++ b/java/com/engflow/internship/cycleexample/input/input.txt @@ -0,0 +1 @@ +Sie stellte das Tschechische Streichholzschächtelchen auf den Tisch, auf den Tisch stellte sie das Tschechische Streichholzschächtelchen \ No newline at end of file diff --git a/java/com/engflow/internship/cycleexample/interface_a/InterfaceA.java b/java/com/engflow/internship/cycleexample/interface_a/InterfaceA.java index ff76a8db..bd3e95b7 100644 --- a/java/com/engflow/internship/cycleexample/interface_a/InterfaceA.java +++ b/java/com/engflow/internship/cycleexample/interface_a/InterfaceA.java @@ -1,5 +1,5 @@ package com.engflow.internship.cycleexample.interface_a; public interface InterfaceA { - void methodA(); + void methodA(String input); } diff --git a/java/com/engflow/internship/cycleexample/interface_b/InterfaceB.java b/java/com/engflow/internship/cycleexample/interface_b/InterfaceB.java index af637e71..6a5c8813 100644 --- a/java/com/engflow/internship/cycleexample/interface_b/InterfaceB.java +++ b/java/com/engflow/internship/cycleexample/interface_b/InterfaceB.java @@ -1,5 +1,5 @@ package com.engflow.internship.cycleexample.interface_b; public interface InterfaceB { - void methodB(); + void methodB(String input); } \ No newline at end of file diff --git a/java/com/engflow/internship/cycleexample/main/BUILD b/java/com/engflow/internship/cycleexample/main/BUILD index 525fb4c6..0f688fb4 100644 --- a/java/com/engflow/internship/cycleexample/main/BUILD +++ b/java/com/engflow/internship/cycleexample/main/BUILD @@ -8,5 +8,8 @@ java_binary( "//java/com/engflow/internship/cycleexample/class_b", "//java/com/engflow/internship/cycleexample/class_c", ], + data = [ + "//java/com/engflow/internship/cycleexample/input", + ], main_class = "com.engflow.internship.cycleexample.main.Main", ) \ No newline at end of file diff --git a/java/com/engflow/internship/cycleexample/main/Main.java b/java/com/engflow/internship/cycleexample/main/Main.java index 9c65885e..5f6816ce 100644 --- a/java/com/engflow/internship/cycleexample/main/Main.java +++ b/java/com/engflow/internship/cycleexample/main/Main.java @@ -4,8 +4,29 @@ import com.engflow.internship.cycleexample.class_b.ClassB; import com.engflow.internship.cycleexample.class_c.ClassC; +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; + public class Main { public static void main(String[] args) { + //Input file path + String fileName = "java/com/engflow/internship/cycleexample/input/input.txt"; + StringBuilder content = new StringBuilder(); + + //Read the input file and store the content in a StringBuilder + try (BufferedReader br = new BufferedReader(new FileReader(fileName))) { + String line; + while ((line = br.readLine()) != null) { + content.append(line).append(" "); + } + } catch (IOException e) { + e.printStackTrace(); + } + + String input = content.toString().trim(); + + // Create instances of ClassA, ClassB, and ClassC ClassC classC = new ClassC(null); ClassB classB = new ClassB(classC); ClassA classA = new ClassA(classB); @@ -13,6 +34,6 @@ public static void main(String[] args) { // Properly initialize classC with classA classC.setClassA(classA); - classA.methodA(); + classA.methodA(input); } } \ No newline at end of file From 9f9d3df7271bd173fcc39bbb9d14ae2dba7cb38d Mon Sep 17 00:00:00 2001 From: Huertas Cadavid Nicolas Fernando <98675931+NicolasHuertas@users.noreply.github.com> Date: Mon, 16 Sep 2024 18:09:33 -0500 Subject: [PATCH 05/11] Update README.md --- java/com/engflow/internship/cycleexample/README.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/java/com/engflow/internship/cycleexample/README.md b/java/com/engflow/internship/cycleexample/README.md index ec1d02d6..6f3cd222 100644 --- a/java/com/engflow/internship/cycleexample/README.md +++ b/java/com/engflow/internship/cycleexample/README.md @@ -28,12 +28,9 @@ The project is organized into several packages, each representing different comp The program takes a text input file and recursively prints each word with each class (`ClassA` prints a word, then `ClassB`, and so on) until the string is empty. The input file should be specified in the `data` attribute of the `java_binary` rule in the `BUILD` file. -Here is an example of how the `Main` class processes the input file: - - ## How to Run Tests To run the tests and gather performance data, use the following Bazel command: ```sh -bazel test //java/com/engflow/internship/cycleexample/class_a:class_a_test \ No newline at end of file +bazel test //java/com/engflow/internship/cycleexample/class_a:class_a_test From 8cd187774fc8f68b44047836d2edbc39cf817e71 Mon Sep 17 00:00:00 2001 From: NicolasHuertas Date: Thu, 3 Oct 2024 21:30:36 -0500 Subject: [PATCH 06/11] Added varying input example --- .../internship/varyinginputs/README.md | 34 ++++++++++ .../internship/varyinginputs/input/BUILD | 5 ++ .../internship/varyinginputs/main/BUILD | 14 ++++ .../internship/varyinginputs/main/Main.java | 30 +++++++++ .../internship/varyinginputs/reader/BUILD | 14 ++++ .../varyinginputs/reader/Reader.java | 45 +++++++++++++ .../varyinginputs/reader/ReaderTest.java | 65 ++++++++++++++++++ .../internship/varyinginputs/writer/BUILD | 14 ++++ .../varyinginputs/writer/Writer.java | 61 +++++++++++++++++ .../varyinginputs/writer/WriterTest.java | 66 +++++++++++++++++++ 10 files changed, 348 insertions(+) create mode 100644 java/com/engflow/internship/varyinginputs/README.md create mode 100644 java/com/engflow/internship/varyinginputs/input/BUILD create mode 100644 java/com/engflow/internship/varyinginputs/main/BUILD create mode 100644 java/com/engflow/internship/varyinginputs/main/Main.java create mode 100644 java/com/engflow/internship/varyinginputs/reader/BUILD create mode 100644 java/com/engflow/internship/varyinginputs/reader/Reader.java create mode 100644 java/com/engflow/internship/varyinginputs/reader/ReaderTest.java create mode 100644 java/com/engflow/internship/varyinginputs/writer/BUILD create mode 100644 java/com/engflow/internship/varyinginputs/writer/Writer.java create mode 100644 java/com/engflow/internship/varyinginputs/writer/WriterTest.java diff --git a/java/com/engflow/internship/varyinginputs/README.md b/java/com/engflow/internship/varyinginputs/README.md new file mode 100644 index 00000000..6bff9660 --- /dev/null +++ b/java/com/engflow/internship/varyinginputs/README.md @@ -0,0 +1,34 @@ +# Varying Inputs Example + +## Overview + +The goal of this example project is to test the performance of Engflow's remote execution and caching service for different input sizes. The project involves creating a specified number of txt files, each containing 100 random characters, using the `Writer` class, and then reading and printing out their contents with the `Reader` class. + +## Project Structure + +- `java/com/engflow/internship/varyinginputs/input`: Directory where the generated `.txt` files are saved. +- `java/com/engflow/internship/varyinginputs/main`: Contains the `Main` class which orchestrates the file creation and reading process. +- `java/com/engflow/internship/varyinginputs/reader`: Contains the `Reader` class responsible for reading the files. +- `java/com/engflow/internship/varyinginputs/writer`: Contains the `Writer` class responsible for writing the files. + +## Usage + +To run the project and specify the number of files to be created, use the following command: + +```sh +bazel run //java/com/engflow/internship/varyinginputs/main -- +``` + +Replace `` with the desired number of files to be created. + +## Example + +To create and read 10 files, you would run: + +```sh +bazel run //java/com/engflow/internship/varyinginputs/main -- 10 +``` + +This command will: +1. Use the `Writer` class to create 10 files, each containing 100 random characters, in the `input` directory. +2. Use the `Reader` class to read and print the contents of these files. \ No newline at end of file diff --git a/java/com/engflow/internship/varyinginputs/input/BUILD b/java/com/engflow/internship/varyinginputs/input/BUILD new file mode 100644 index 00000000..4b9e382f --- /dev/null +++ b/java/com/engflow/internship/varyinginputs/input/BUILD @@ -0,0 +1,5 @@ +filegroup( + name = "input", + srcs = glob(["*.txt"]), + visibility = ["//visibility:public"], +) \ No newline at end of file diff --git a/java/com/engflow/internship/varyinginputs/main/BUILD b/java/com/engflow/internship/varyinginputs/main/BUILD new file mode 100644 index 00000000..677dd87d --- /dev/null +++ b/java/com/engflow/internship/varyinginputs/main/BUILD @@ -0,0 +1,14 @@ +load("@rules_java//java:defs.bzl", "java_binary") + +java_binary( + name = "main", + srcs = ["Main.java"], + deps = [ + "//java/com/engflow/internship/varyinginputs/reader", + "//java/com/engflow/internship/varyinginputs/writer", + ], + data = [ + "//java/com/engflow/internship/varyinginputs/input", + ], + main_class = "com.engflow.internship.varyinginputs.main.Main", +) \ No newline at end of file diff --git a/java/com/engflow/internship/varyinginputs/main/Main.java b/java/com/engflow/internship/varyinginputs/main/Main.java new file mode 100644 index 00000000..ba857681 --- /dev/null +++ b/java/com/engflow/internship/varyinginputs/main/Main.java @@ -0,0 +1,30 @@ +package com.engflow.internship.varyinginputs.main; + +import com.engflow.internship.varyinginputs.reader.Reader; +import com.engflow.internship.varyinginputs.writer.Writer; + +public class Main { + + public static void main(String[] args) { + if (args.length < 1) { + System.out.println("Please provide the number of files as an argument."); + return; + } + + int numberOfFiles; + try { + numberOfFiles = Integer.parseInt(args[0]); + } catch (NumberFormatException e) { + System.out.println("Invalid number format: " + args[0]); + return; + } + + Writer writer = new Writer(); + Reader reader = new Reader(); + + String filePath = "java/com/engflow/internship/varyinginputs/input"; + + writer.writeFiles(numberOfFiles, filePath); + reader.readFiles(filePath); + } +} \ No newline at end of file diff --git a/java/com/engflow/internship/varyinginputs/reader/BUILD b/java/com/engflow/internship/varyinginputs/reader/BUILD new file mode 100644 index 00000000..8aaf090b --- /dev/null +++ b/java/com/engflow/internship/varyinginputs/reader/BUILD @@ -0,0 +1,14 @@ +java_library( + name = "reader", + srcs = ["Reader.java"], + visibility = ["//visibility:public"], +) + +java_test( + name = "reader_test", + srcs = ["ReaderTest.java"], + test_class = "com.engflow.internship.varyinginputs.reader.ReaderTest", + deps = [ + ":reader", + ], +) \ No newline at end of file diff --git a/java/com/engflow/internship/varyinginputs/reader/Reader.java b/java/com/engflow/internship/varyinginputs/reader/Reader.java new file mode 100644 index 00000000..a6d0e376 --- /dev/null +++ b/java/com/engflow/internship/varyinginputs/reader/Reader.java @@ -0,0 +1,45 @@ +package com.engflow.internship.varyinginputs.reader; + +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.io.BufferedReader; + +public class Reader { + + /** + * Reads the content of all files in the specified directory and prints it to the console. + * @param inputPath + */ + public void readFiles(String inputPath) { + File directory = new File(inputPath); + + // Check if the directory exists and is a directory + if (!directory.exists() || !directory.isDirectory()) { + System.out.println("Invalid directory path: " + inputPath); + return; + } + + // List all files in the directory and check if there are any + File[] files = directory.listFiles(); + if (files == null || files.length == 0) { + System.out.println("No files found in the directory: " + inputPath); + return; + } + + // Read the content of each file and print it to the console + for (File file : files) { + if (file.isFile()) { + try (BufferedReader reader = new BufferedReader(new FileReader(file))) { + String line; + System.out.println("Reading file: " + file.getName()); + while ((line = reader.readLine()) != null) { + System.out.println(line); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } +} \ No newline at end of file diff --git a/java/com/engflow/internship/varyinginputs/reader/ReaderTest.java b/java/com/engflow/internship/varyinginputs/reader/ReaderTest.java new file mode 100644 index 00000000..ef6db103 --- /dev/null +++ b/java/com/engflow/internship/varyinginputs/reader/ReaderTest.java @@ -0,0 +1,65 @@ +package com.engflow.internship.varyinginputs.reader; + +import org.junit.Test; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import static org.junit.Assert.assertTrue; + +public class ReaderTest { + + @Test + public void testReadFilesPrintsFileContents() throws IOException { + Reader reader = new Reader(); + String inputPath = "test_input"; + String fileName = "testFile.txt"; + String fileContent = "Hello, World!"; + + // Set up test files + File directory = new File(inputPath); + directory.mkdirs(); + File testFile = new File(inputPath + "/" + fileName); + try (FileWriter writer = new FileWriter(testFile)) { + writer.write(fileContent); + } + + // Capture the output + java.io.ByteArrayOutputStream outContent = new java.io.ByteArrayOutputStream(); + System.setOut(new java.io.PrintStream(outContent)); + + // Run the method + reader.readFiles(inputPath); + + // Verify the output + String expectedOutput = "Reading file: " + fileName + "\n" + fileContent + "\n"; + assertTrue(outContent.toString().contains(expectedOutput)); + + // Clean up after test + testFile.delete(); + directory.delete(); + } + + @Test + public void testReadFilesHandlesEmptyDirectory() { + Reader reader = new Reader(); + String inputPath = "empty_test_input"; + + // Set up empty directory + File directory = new File(inputPath); + directory.mkdirs(); + + // Capture the output + java.io.ByteArrayOutputStream outContent = new java.io.ByteArrayOutputStream(); + System.setOut(new java.io.PrintStream(outContent)); + + // Run the method + reader.readFiles(inputPath); + + // Verify the output + String expectedOutput = "No files found in the directory: " + inputPath + "\n"; + assertTrue(outContent.toString().contains(expectedOutput)); + + // Clean up after test + directory.delete(); + } +} \ No newline at end of file diff --git a/java/com/engflow/internship/varyinginputs/writer/BUILD b/java/com/engflow/internship/varyinginputs/writer/BUILD new file mode 100644 index 00000000..8391c14a --- /dev/null +++ b/java/com/engflow/internship/varyinginputs/writer/BUILD @@ -0,0 +1,14 @@ +java_library( + name = "writer", + srcs = ["Writer.java"], + visibility = ["//visibility:public"], +) + +java_test( + name = "writer_test", + srcs = ["WriterTest.java"], + test_class = "com.engflow.internship.varyinginputs.writer.WriterTest", + deps = [ + ":writer", + ], +) \ No newline at end of file diff --git a/java/com/engflow/internship/varyinginputs/writer/Writer.java b/java/com/engflow/internship/varyinginputs/writer/Writer.java new file mode 100644 index 00000000..8df6380d --- /dev/null +++ b/java/com/engflow/internship/varyinginputs/writer/Writer.java @@ -0,0 +1,61 @@ +package com.engflow.internship.varyinginputs.writer; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Random; +import java.util.UUID; + +public class Writer { + + /** + * Write the specified number of files to the output path. + * @param numberOfFiles + * @param outputPath + */ + public void writeFiles(int numberOfFiles, String outputPath) { + File directory = new File(outputPath); + + if (!directory.exists()) { + directory.mkdirs(); + } + + // list all files in the directory and count them + File[] existingFiles = directory.listFiles(); + int existingFilesCount = existingFiles != null ? existingFiles.length : 0; + + Random random = new Random(); + + // create new files if the number of existing files is less than the required number + if (existingFilesCount < numberOfFiles) { + for (int i = existingFilesCount; i < numberOfFiles; i++) { + // create a new file with a unique name to avoid conflicts + String fileName = outputPath + "/file" + UUID.randomUUID() + ".txt"; + File file = new File(fileName); + + try { + // write 100 random characters to the file + file.createNewFile(); + FileWriter writer = new FileWriter(file); + for (int j = 0; j < 100; j++) { + char randomChar = (char) (random.nextInt(26) + 'a'); + writer.write(randomChar); + } + writer.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + // delete files if the number of existing files is greater than the required number + else if (existingFilesCount > numberOfFiles) { + while (existingFilesCount > numberOfFiles) { + int fileIndex = random.nextInt(existingFilesCount); + File fileToDelete = existingFiles[fileIndex]; + if (fileToDelete.delete()) { + existingFilesCount--; + } + } + } + } +} \ No newline at end of file diff --git a/java/com/engflow/internship/varyinginputs/writer/WriterTest.java b/java/com/engflow/internship/varyinginputs/writer/WriterTest.java new file mode 100644 index 00000000..eb59f542 --- /dev/null +++ b/java/com/engflow/internship/varyinginputs/writer/WriterTest.java @@ -0,0 +1,66 @@ +package com.engflow.internship.varyinginputs.writer; + +import org.junit.Test; +import java.io.File; +import java.io.IOException; +import static org.junit.Assert.assertEquals; + +public class WriterTest { + + @Test + public void testWriteFilesCreatesCorrectNumberOfFiles() throws IOException { + Writer writer = new Writer(); + String outputPath = "test_output"; + int numberOfFiles = 5; + + // Clean up before test + File directory = new File(outputPath); + if (directory.exists()) { + for (File file : directory.listFiles()) { + file.delete(); + } + directory.delete(); + } + + // Run the method + writer.writeFiles(numberOfFiles, outputPath); + + // Verify the number of files created + File[] files = new File(outputPath).listFiles(); + assertEquals(numberOfFiles, files.length); + + // Clean up after test + for (File file : files) { + file.delete(); + } + new File(outputPath).delete(); + } + + @Test + public void testWriteFilesDeletesExcessFiles() throws IOException { + Writer writer = new Writer(); + String outputPath = "test_output"; + int initialNumberOfFiles = 10; + int finalNumberOfFiles = 5; + + // Create initial files + File directory = new File(outputPath); + directory.mkdirs(); + for (int i = 0; i < initialNumberOfFiles; i++) { + new File(outputPath + "/file" + i + ".txt").createNewFile(); + } + + // Run the method + writer.writeFiles(finalNumberOfFiles, outputPath); + + // Verify the number of files after deletion + File[] files = new File(outputPath).listFiles(); + assertEquals(finalNumberOfFiles, files.length); + + // Clean up after test + for (File file : files) { + file.delete(); + } + new File(outputPath).delete(); + } +} \ No newline at end of file From 33ce4dbb363c3fdac3276de24d0a4194a356bfa7 Mon Sep 17 00:00:00 2001 From: NicolasHuertas Date: Sat, 5 Oct 2024 20:36:26 -0500 Subject: [PATCH 07/11] Example using inputs from a genrule --- .../com/engflow/internship/setinput/README.md | 0 .../engflow/internship/setinput/genfile/BUILD | 13 ++++++ .../internship/setinput/genreader/BUILD | 5 +++ .../setinput/genreader/GenReader.java | 45 +++++++++++++++++++ .../engflow/internship/setinput/main/BUILD | 13 ++++++ .../internship/setinput/main/Main.java | 14 ++++++ 6 files changed, 90 insertions(+) create mode 100644 java/com/engflow/internship/setinput/README.md create mode 100644 java/com/engflow/internship/setinput/genfile/BUILD create mode 100644 java/com/engflow/internship/setinput/genreader/BUILD create mode 100644 java/com/engflow/internship/setinput/genreader/GenReader.java create mode 100644 java/com/engflow/internship/setinput/main/BUILD create mode 100644 java/com/engflow/internship/setinput/main/Main.java diff --git a/java/com/engflow/internship/setinput/README.md b/java/com/engflow/internship/setinput/README.md new file mode 100644 index 00000000..e69de29b diff --git a/java/com/engflow/internship/setinput/genfile/BUILD b/java/com/engflow/internship/setinput/genfile/BUILD new file mode 100644 index 00000000..d65eb193 --- /dev/null +++ b/java/com/engflow/internship/setinput/genfile/BUILD @@ -0,0 +1,13 @@ +NUM_FILES = 10 + +[genrule( + name = "benchmark_test_file" + str(x), + outs = ["benchmark_test_file" + str(x) + ".txt"], + cmd_bash = "echo 'benchmark test file " + str(x) + "' > $@", +) for x in range(1,NUM_FILES+1)] + +filegroup( + name = "genfile", + srcs = glob(["genfile/benchmark_test_file*.txt"]), + visibility = ["//visibility:public"], +) \ No newline at end of file diff --git a/java/com/engflow/internship/setinput/genreader/BUILD b/java/com/engflow/internship/setinput/genreader/BUILD new file mode 100644 index 00000000..42c01404 --- /dev/null +++ b/java/com/engflow/internship/setinput/genreader/BUILD @@ -0,0 +1,5 @@ +java_library( + name = "genreader", + srcs = ["GenReader.java"], + visibility = ["//visibility:public"], +) \ No newline at end of file diff --git a/java/com/engflow/internship/setinput/genreader/GenReader.java b/java/com/engflow/internship/setinput/genreader/GenReader.java new file mode 100644 index 00000000..c3dd9f86 --- /dev/null +++ b/java/com/engflow/internship/setinput/genreader/GenReader.java @@ -0,0 +1,45 @@ +package com.engflow.internship.setinput.genreader; + +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.io.BufferedReader; + +public class GenReader { + + /** + * Reads the content of all files in the specified directory and prints it to the console. + * @param inputPath + */ + public void readFiles(String inputPath) { + File directory = new File(inputPath); + + // Check if the directory exists and is a directory + if (!directory.exists() || !directory.isDirectory()) { + System.out.println("Invalid directory path: " + inputPath); + return; + } + + // List all files in the directory and check if there are any + File[] files = directory.listFiles(); + if (files == null || files.length == 0) { + System.out.println("No files found in the directory: " + inputPath); + return; + } + + // Read the content of each file and print it to the console + for (File file : files) { + if (file.isFile()) { + try (BufferedReader reader = new BufferedReader(new FileReader(file))) { + String line; + System.out.println("Reading file: " + file.getName()); + while ((line = reader.readLine()) != null) { + System.out.println(line); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } +} \ No newline at end of file diff --git a/java/com/engflow/internship/setinput/main/BUILD b/java/com/engflow/internship/setinput/main/BUILD new file mode 100644 index 00000000..0d2524aa --- /dev/null +++ b/java/com/engflow/internship/setinput/main/BUILD @@ -0,0 +1,13 @@ +load("@rules_java//java:defs.bzl", "java_binary") + +java_binary( + name = "main", + srcs = ["Main.java"], + deps = [ + "//java/com/engflow/internship/setinput/genreader", + ], + data = [ + "//java/com/engflow/internship/setinput/genfile:genfile", + ], + main_class = "com.engflow.internship.setinput.main.Main", +) \ No newline at end of file diff --git a/java/com/engflow/internship/setinput/main/Main.java b/java/com/engflow/internship/setinput/main/Main.java new file mode 100644 index 00000000..4c8b2140 --- /dev/null +++ b/java/com/engflow/internship/setinput/main/Main.java @@ -0,0 +1,14 @@ +package com.engflow.internship.setinput.main; + +import com.engflow.internship.setinput.genreader.GenReader; + +public class Main { + + public static void main(String[] args) { + GenReader reader = new GenReader(); + + String filePath = "//java/com/engflow/internship/setinput/genfile:genfile"; + + reader.readFiles(filePath); + } +} \ No newline at end of file From b1c8d09150a5c412fffd62543630311af0dff5e5 Mon Sep 17 00:00:00 2001 From: NicolasHuertas Date: Sun, 6 Oct 2024 12:33:10 -0500 Subject: [PATCH 08/11] fixed genfile path error --- .../com/engflow/internship/setinput/README.md | 26 ++++++++++++ .../engflow/internship/setinput/genfile/BUILD | 5 +-- .../setinput/genreader/GenReader.java | 40 +++++++------------ .../engflow/internship/setinput/main/BUILD | 4 +- .../internship/setinput/main/Main.java | 26 ++++++++++-- 5 files changed, 67 insertions(+), 34 deletions(-) diff --git a/java/com/engflow/internship/setinput/README.md b/java/com/engflow/internship/setinput/README.md index e69de29b..da075b01 100644 --- a/java/com/engflow/internship/setinput/README.md +++ b/java/com/engflow/internship/setinput/README.md @@ -0,0 +1,26 @@ +# Set Inputs Example + +## Overview + +The goal of this example project is to test the performance of Engflow's remote execution and caching service for different input sizes. The project contains a genrule that writes a set number of `.txt` files in the `genfile` directory. The content of this files is then read and printed out with the `Reader` class. + +## Project Structure + +- `java/com/engflow/internship/setinput/genfile`: Directory where the `.txt` files generated by the genrule are stored. +- `java/com/engflow/internship/varyinginputs/main`: Contains the `Main` class which orchestrates the reading process. +- `java/com/engflow/internship/varyinginputs/reader`: Contains the `Reader` class responsible for reading the files. + +## Usage + +To generate the test files, build the filegroup target: +```sh +bazel build //java/com/engflow/internship/setinput/genfile +``` + +Then, the program can be run with the following command: + +```sh +bazel run //java/com/engflow/internship/varyinginputs/main +``` + +To modify the amount of files generated, change the value of the `NUM_FILES` in the `BUILD` file inside the `genfile` directory. \ No newline at end of file diff --git a/java/com/engflow/internship/setinput/genfile/BUILD b/java/com/engflow/internship/setinput/genfile/BUILD index d65eb193..dbfb5d29 100644 --- a/java/com/engflow/internship/setinput/genfile/BUILD +++ b/java/com/engflow/internship/setinput/genfile/BUILD @@ -1,4 +1,4 @@ -NUM_FILES = 10 +NUM_FILES = 16 [genrule( name = "benchmark_test_file" + str(x), @@ -8,6 +8,5 @@ NUM_FILES = 10 filegroup( name = "genfile", - srcs = glob(["genfile/benchmark_test_file*.txt"]), - visibility = ["//visibility:public"], + srcs = [":benchmark_test_file" + str(x) for x in range(1,NUM_FILES+1)], ) \ No newline at end of file diff --git a/java/com/engflow/internship/setinput/genreader/GenReader.java b/java/com/engflow/internship/setinput/genreader/GenReader.java index c3dd9f86..c2007d6a 100644 --- a/java/com/engflow/internship/setinput/genreader/GenReader.java +++ b/java/com/engflow/internship/setinput/genreader/GenReader.java @@ -8,38 +8,28 @@ public class GenReader { /** - * Reads the content of all files in the specified directory and prints it to the console. + * Reads the content of the specified file and prints it to the console. * @param inputPath */ public void readFiles(String inputPath) { - File directory = new File(inputPath); + File file = new File(inputPath); - // Check if the directory exists and is a directory - if (!directory.exists() || !directory.isDirectory()) { - System.out.println("Invalid directory path: " + inputPath); + // Check if the file exists and is a file + if (!file.exists() || !file.isFile()) { + System.out.println("Invalid file path: " + inputPath + "\n Absolute path: " + file.getAbsolutePath()+ + "\n File: " + file); return; } - // List all files in the directory and check if there are any - File[] files = directory.listFiles(); - if (files == null || files.length == 0) { - System.out.println("No files found in the directory: " + inputPath); - return; - } - - // Read the content of each file and print it to the console - for (File file : files) { - if (file.isFile()) { - try (BufferedReader reader = new BufferedReader(new FileReader(file))) { - String line; - System.out.println("Reading file: " + file.getName()); - while ((line = reader.readLine()) != null) { - System.out.println(line); - } - } catch (IOException e) { - e.printStackTrace(); - } + // Read the content of the file and print it to the console + try (BufferedReader reader = new BufferedReader(new FileReader(file))) { + String line; + System.out.println("Reading file: " + file.getName()); + while ((line = reader.readLine()) != null) { + System.out.println(line); } + } catch (IOException e) { + e.printStackTrace(); } } -} \ No newline at end of file +} diff --git a/java/com/engflow/internship/setinput/main/BUILD b/java/com/engflow/internship/setinput/main/BUILD index 0d2524aa..7a094ceb 100644 --- a/java/com/engflow/internship/setinput/main/BUILD +++ b/java/com/engflow/internship/setinput/main/BUILD @@ -6,8 +6,6 @@ java_binary( deps = [ "//java/com/engflow/internship/setinput/genreader", ], - data = [ - "//java/com/engflow/internship/setinput/genfile:genfile", - ], + data = glob(["java/com/engflow/internship/setinput/genfile/*.txt"]), main_class = "com.engflow.internship.setinput.main.Main", ) \ No newline at end of file diff --git a/java/com/engflow/internship/setinput/main/Main.java b/java/com/engflow/internship/setinput/main/Main.java index 4c8b2140..d3283240 100644 --- a/java/com/engflow/internship/setinput/main/Main.java +++ b/java/com/engflow/internship/setinput/main/Main.java @@ -2,13 +2,33 @@ import com.engflow.internship.setinput.genreader.GenReader; +import java.nio.file.Paths; +import java.nio.file.Files; +import java.io.IOException; + public class Main { public static void main(String[] args) { - GenReader reader = new GenReader(); + String genfilePath = "java/com/engflow/internship/setinput/genfile"; // Path relative to bazel-bin + String workspacePath = System.getenv("BUILD_WORKING_DIRECTORY"); + //System.out.println("Workspace path: " + workspacePath); - String filePath = "//java/com/engflow/internship/setinput/genfile:genfile"; + if (workspacePath == null) { + System.out.println("Workspace path could not be determined."); + return; + } - reader.readFiles(filePath); + String bazelBinPath = Paths.get(workspacePath, "bazel-bin").toString(); + //System.out.println("Bazel-bin path: " + bazelBinPath); + String fullPath = Paths.get(bazelBinPath, genfilePath).toString(); + + GenReader reader = new GenReader(); + try { + Files.list(Paths.get(fullPath)) + .filter(Files::isRegularFile) + .forEach(file -> reader.readFiles(file.toString())); + } catch (IOException e) { + e.printStackTrace(); + } } } \ No newline at end of file From 2905e21c0c1e3bf62ee59b85a8b9c20e1b0ea276 Mon Sep 17 00:00:00 2001 From: NicolasHuertas Date: Sun, 6 Oct 2024 14:09:55 -0500 Subject: [PATCH 09/11] Added biinary input example --- java/com/engflow/internship/binaryinput/BUILD | 32 ++++++++++++ .../engflow/internship/binaryinput/Main.java | 21 ++++++++ .../engflow/internship/binaryinput/README.md | 52 +++++++++++++++++++ 3 files changed, 105 insertions(+) create mode 100644 java/com/engflow/internship/binaryinput/BUILD create mode 100644 java/com/engflow/internship/binaryinput/Main.java create mode 100644 java/com/engflow/internship/binaryinput/README.md diff --git a/java/com/engflow/internship/binaryinput/BUILD b/java/com/engflow/internship/binaryinput/BUILD new file mode 100644 index 00000000..6572fbb9 --- /dev/null +++ b/java/com/engflow/internship/binaryinput/BUILD @@ -0,0 +1,32 @@ +load("@rules_java//java:defs.bzl", "java_binary", "java_library") + +NUM_FILES = 10 + +#Main class +java_binary( + name = "main", + srcs = ["Main.java"], + main_class = "com.engflow.internship.binaryinput.Main", + deps = [ + ":genbinary" + ], + args = [str(NUM_FILES)], +) + +#Generates a number of java files based on the value of NUM_FILES +#Each file is named HelloX.java where X is the number of the file +#Each file contains a class with a greetNum method that prints "Hello" + the number of the file +[genrule( + name = "Hello" + str(x), + outs = ["Hello" + str(x) + ".java"], + cmd_bash = "echo 'package com.engflow.internship.binaryinput;" + "\n" + + "public class Hello" + str(x) + + " { public static void greetNum() { System.out.println(\"Hello " + str(x) + "\"); } }' > $@", +) for x in range(1,NUM_FILES+1)] + +#Generates a java library that contains all the generated java files +java_library( + name = "genbinary", + srcs = [":Hello" + str(x) + ".java" for x in range(1,NUM_FILES+1)], + visibility = ["//visibility:public"], +) \ No newline at end of file diff --git a/java/com/engflow/internship/binaryinput/Main.java b/java/com/engflow/internship/binaryinput/Main.java new file mode 100644 index 00000000..ca2374ba --- /dev/null +++ b/java/com/engflow/internship/binaryinput/Main.java @@ -0,0 +1,21 @@ +package com.engflow.internship.binaryinput; + +import java.lang.reflect.InvocationTargetException; + +public class Main { + public static void main(String[] args) { + try { + // args[0] is the number of files to read + int numFiles = Integer.parseInt(args[0]); + + // Load and run the greetNum method from each class + for(int i = 1; i <= numFiles; i++){ + Class clazz = Class.forName("com.engflow.internship.binaryinput.Hello" + i); + clazz.getMethod("greetNum").invoke(null); + } + + } catch (ClassNotFoundException | InvocationTargetException | IllegalAccessException | NoSuchMethodException e) { + throw new RuntimeException(e); + } + } +} diff --git a/java/com/engflow/internship/binaryinput/README.md b/java/com/engflow/internship/binaryinput/README.md new file mode 100644 index 00000000..e2bd8d72 --- /dev/null +++ b/java/com/engflow/internship/binaryinput/README.md @@ -0,0 +1,52 @@ +# Multiple Binary Input Example + +## Overview + +The goal of this example project is to test the performance of Engflow's remote execution and caching service based on the number of input binary files in the dependency graph. The project contains a `genrule` that generates a specified number of Java binaries for the `genbinary` Java library, which are then listed as dependencies in the main binary. The `Main.java` file loops through each generated class and calls its `greetNum` method. + +## Project Structure + +- `java/com/engflow/internship/binaryinput/Main.java`: Main class that dynamically loads and invokes methods from generated classes. +- `java/com/engflow/internship/binaryinput/BUILD`: Bazel build file for the `main` java binary and the `genbinary` library. + +## Usage + +To generate the test files, build the `genbinary` library using the `genrule`: +```sh +bazel build //java/com/engflow/internship/binaryinput:genbinary +``` + +Then, the program can be run with the following command: +```sh +bazel run //java/com/engflow/internship/binaryinput:main +``` + +## How It Works + +1. **Generation of Java Binaries:** + - The `genrule` in the `BUILD` file generates a specified number of Java classes (`Hello1.java`, `Hello2.java`, ..., `HelloN.java`). + - Each generated class contains a `greetNum` method that prints a unique message. + +2. **Main Class Execution:** + - The `Main.java` file in `binaryinput` dynamically loads each generated class using reflection. + - It then invokes the `greetNum` method of each class, printing the corresponding message. + +## Configuration + +The number of generated files is controlled by the `NUM_FILES` variable in the `BUILD` file of the `binaryinput` package. Modify this variable to change the number of generated classes and observe the performance impact on Engflow's remote execution and caching service. + +## Example + +To generate and run the program with 10 input binary files: + +1. Set `NUM_FILES` to 10 in `java/com/engflow/internship/binaryinput/BUILD`. +2. Build the `genbinary` library: + ```sh + bazel build //java/com/engflow/internship/binaryinput:genbinary + ``` +3. Run the `main` binary: + ```sh + bazel run //java/com/engflow/internship/binaryinput:main + ``` + +This will generate 10 Java classes, build the `genbinary` library, and run the `main` binary, which will print messages from each generated class. \ No newline at end of file From 0a4819a17f4b381cb66ebd52fa599742bc8c3937 Mon Sep 17 00:00:00 2001 From: NicolasHuertas Date: Wed, 23 Oct 2024 14:53:14 -0500 Subject: [PATCH 10/11] changed depedency structure --- .bazelrc | 10 +++++++ java/com/engflow/internship/binaryinput/BUILD | 30 +++++++++---------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/.bazelrc b/.bazelrc index 86b455cf..1dbe80e4 100644 --- a/.bazelrc +++ b/.bazelrc @@ -75,6 +75,16 @@ build:magnesite_bes --bes_backend=grpcs://magnesite.cluster.engflow.com build:magnesite_bes --bes_lifecycle_events build:magnesite_bes --bes_results_url=https://magnesite.cluster.engflow.com/invocation/ + +# EngFlow Remote caching +build:engflow-rc --remote_cache=grpc://127.0.0.1:8080 +# EngFlow BES forwarding +build:engflow-bes --bes_backend=grpc://127.0.0.1:8080 +build:engflow-bes --bes_results_url=http://127.0.0.1:8080/invocation/ +# EngFlow Remote caching and BES forwarding +build:engflow --config=engflow-rc +build:engflow --config=engflow-bes + # To authenticate with the clusters above, create a .bazelrc.user file. # This file is not checked into Git because it refers to local file system paths. # diff --git a/java/com/engflow/internship/binaryinput/BUILD b/java/com/engflow/internship/binaryinput/BUILD index 6572fbb9..8abd0848 100644 --- a/java/com/engflow/internship/binaryinput/BUILD +++ b/java/com/engflow/internship/binaryinput/BUILD @@ -1,17 +1,6 @@ load("@rules_java//java:defs.bzl", "java_binary", "java_library") -NUM_FILES = 10 - -#Main class -java_binary( - name = "main", - srcs = ["Main.java"], - main_class = "com.engflow.internship.binaryinput.Main", - deps = [ - ":genbinary" - ], - args = [str(NUM_FILES)], -) +NUM_FILES = 500 #Generates a number of java files based on the value of NUM_FILES #Each file is named HelloX.java where X is the number of the file @@ -25,8 +14,19 @@ java_binary( ) for x in range(1,NUM_FILES+1)] #Generates a java library that contains all the generated java files -java_library( - name = "genbinary", +[java_library( + name = "genbinary" + str(x), srcs = [":Hello" + str(x) + ".java" for x in range(1,NUM_FILES+1)], visibility = ["//visibility:public"], -) \ No newline at end of file +) for x in range(1,NUM_FILES+1)] + +#Main class +java_binary( + name = "main", + srcs = ["Main.java"], + main_class = "com.engflow.internship.binaryinput.Main", + deps = [ + ":genbinary" + str(x) for x in range(1,NUM_FILES+1) + ], + args = [str(NUM_FILES)], +) From 7ef5e68422b977eb0f06ffb5696f26c41b04867a Mon Sep 17 00:00:00 2001 From: NicolasHuertas Date: Thu, 24 Oct 2024 20:02:13 -0500 Subject: [PATCH 11/11] reverting changes on .bazelrc --- .bazelrc | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/.bazelrc b/.bazelrc index 1dbe80e4..86b455cf 100644 --- a/.bazelrc +++ b/.bazelrc @@ -75,16 +75,6 @@ build:magnesite_bes --bes_backend=grpcs://magnesite.cluster.engflow.com build:magnesite_bes --bes_lifecycle_events build:magnesite_bes --bes_results_url=https://magnesite.cluster.engflow.com/invocation/ - -# EngFlow Remote caching -build:engflow-rc --remote_cache=grpc://127.0.0.1:8080 -# EngFlow BES forwarding -build:engflow-bes --bes_backend=grpc://127.0.0.1:8080 -build:engflow-bes --bes_results_url=http://127.0.0.1:8080/invocation/ -# EngFlow Remote caching and BES forwarding -build:engflow --config=engflow-rc -build:engflow --config=engflow-bes - # To authenticate with the clusters above, create a .bazelrc.user file. # This file is not checked into Git because it refers to local file system paths. #