Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
E
ExecutorServiceHW
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
laith.asaad
ExecutorServiceHW
Commits
a7f4030f
Commit
a7f4030f
authored
Nov 15, 2023
by
Lenovo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
final step with junit tester
parent
facfc59b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
190 additions
and
3 deletions
+190
-3
workspace.xml
.idea/workspace.xml
+78
-3
ParallelSummersTest.java
src/test/java/ParallelSummersTest.java
+112
-0
No files found.
.idea/workspace.xml
View file @
a7f4030f
...
...
@@ -4,7 +4,10 @@
<option
name=
"autoReloadType"
value=
"SELECTIVE"
/>
</component>
<component
name=
"ChangeListManager"
>
<list
default=
"true"
id=
"2698c064-0a25-4fa9-b373-a085833ed750"
name=
"Changes"
comment=
"third step"
/>
<list
default=
"true"
id=
"2698c064-0a25-4fa9-b373-a085833ed750"
name=
"Changes"
comment=
"fourth step with main tester"
>
<change
afterPath=
"$PROJECT_DIR$/src/test/java/ParallelSummersTest.java"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/.idea/workspace.xml"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/.idea/workspace.xml"
afterDir=
"false"
/>
</list>
<option
name=
"SHOW_DIALOG"
value=
"false"
/>
<option
name=
"HIGHLIGHT_CONFLICTS"
value=
"true"
/>
<option
name=
"HIGHLIGHT_NON_ACTIVE_CHANGELIST"
value=
"false"
/>
...
...
@@ -23,6 +26,9 @@
<component
name=
"MarkdownSettingsMigration"
>
<option
name=
"stateVersion"
value=
"1"
/>
</component>
<component
name=
"ProblemsViewState"
>
<option
name=
"selectedTabId"
value=
"CurrentFile"
/>
</component>
<component
name=
"ProjectId"
id=
"2YDqGbLJfns60iFSnvDoXlK7JEf"
/>
<component
name=
"ProjectLevelVcsManager"
settingsEditedManually=
"true"
/>
<component
name=
"ProjectViewState"
>
...
...
@@ -36,6 +42,67 @@
"SHARE_PROJECT_CONFIGURATION_FILES": "true"
}
}]]>
</component>
<component
name=
"RunManager"
selected=
"JUnit.ParallelSummersTest.testSixteenThread"
>
<configuration
name=
"ParallelSummersTest.testEightThread"
type=
"JUnit"
factoryName=
"JUnit"
temporary=
"true"
nameIsGenerated=
"true"
>
<module
name=
"ExecutorServiceHW"
/>
<option
name=
"PACKAGE_NAME"
value=
""
/>
<option
name=
"MAIN_CLASS_NAME"
value=
"ParallelSummersTest"
/>
<option
name=
"METHOD_NAME"
value=
"testEightThread"
/>
<option
name=
"TEST_OBJECT"
value=
"method"
/>
<method
v=
"2"
>
<option
name=
"Make"
enabled=
"true"
/>
</method>
</configuration>
<configuration
name=
"ParallelSummersTest.testFourThread"
type=
"JUnit"
factoryName=
"JUnit"
temporary=
"true"
nameIsGenerated=
"true"
>
<module
name=
"ExecutorServiceHW"
/>
<option
name=
"PACKAGE_NAME"
value=
""
/>
<option
name=
"MAIN_CLASS_NAME"
value=
"ParallelSummersTest"
/>
<option
name=
"METHOD_NAME"
value=
"testFourThread"
/>
<option
name=
"TEST_OBJECT"
value=
"method"
/>
<method
v=
"2"
>
<option
name=
"Make"
enabled=
"true"
/>
</method>
</configuration>
<configuration
name=
"ParallelSummersTest.testSingleThread"
type=
"JUnit"
factoryName=
"JUnit"
temporary=
"true"
nameIsGenerated=
"true"
>
<module
name=
"ExecutorServiceHW"
/>
<option
name=
"PACKAGE_NAME"
value=
""
/>
<option
name=
"MAIN_CLASS_NAME"
value=
"ParallelSummersTest"
/>
<option
name=
"METHOD_NAME"
value=
"testSingleThread"
/>
<option
name=
"TEST_OBJECT"
value=
"method"
/>
<method
v=
"2"
>
<option
name=
"Make"
enabled=
"true"
/>
</method>
</configuration>
<configuration
name=
"ParallelSummersTest.testSixteenThread"
type=
"JUnit"
factoryName=
"JUnit"
temporary=
"true"
nameIsGenerated=
"true"
>
<module
name=
"ExecutorServiceHW"
/>
<option
name=
"PACKAGE_NAME"
value=
""
/>
<option
name=
"MAIN_CLASS_NAME"
value=
"ParallelSummersTest"
/>
<option
name=
"METHOD_NAME"
value=
"testSixteenThread"
/>
<option
name=
"TEST_OBJECT"
value=
"method"
/>
<method
v=
"2"
>
<option
name=
"Make"
enabled=
"true"
/>
</method>
</configuration>
<configuration
name=
"ParallelSummersTest.testTwoThread"
type=
"JUnit"
factoryName=
"JUnit"
temporary=
"true"
nameIsGenerated=
"true"
>
<module
name=
"ExecutorServiceHW"
/>
<option
name=
"PACKAGE_NAME"
value=
""
/>
<option
name=
"MAIN_CLASS_NAME"
value=
"ParallelSummersTest"
/>
<option
name=
"METHOD_NAME"
value=
"testTwoThread"
/>
<option
name=
"TEST_OBJECT"
value=
"method"
/>
<method
v=
"2"
>
<option
name=
"Make"
enabled=
"true"
/>
</method>
</configuration>
<recent_temporary>
<list>
<item
itemvalue=
"JUnit.ParallelSummersTest.testSixteenThread"
/>
<item
itemvalue=
"JUnit.ParallelSummersTest.testEightThread"
/>
<item
itemvalue=
"JUnit.ParallelSummersTest.testFourThread"
/>
<item
itemvalue=
"JUnit.ParallelSummersTest.testTwoThread"
/>
<item
itemvalue=
"JUnit.ParallelSummersTest.testSingleThread"
/>
</list>
</recent_temporary>
</component>
<component
name=
"SpellCheckerSettings"
RuntimeDictionaries=
"0"
Folders=
"0"
CustomDictionaries=
"0"
DefaultDictionary=
"application-level"
UseSingleDictionary=
"true"
transferred=
"true"
/>
<component
name=
"TaskManager"
>
<task
active=
"true"
id=
"Default"
summary=
"Default task"
>
...
...
@@ -66,7 +133,14 @@
<option
name=
"project"
value=
"LOCAL"
/>
<updated>
1700071001900
</updated>
</task>
<option
name=
"localTasksCounter"
value=
"4"
/>
<task
id=
"LOCAL-00004"
summary=
"fourth step with main tester"
>
<created>
1700071261635
</created>
<option
name=
"number"
value=
"00004"
/>
<option
name=
"presentableId"
value=
"LOCAL-00004"
/>
<option
name=
"project"
value=
"LOCAL"
/>
<updated>
1700071261635
</updated>
</task>
<option
name=
"localTasksCounter"
value=
"5"
/>
<servers
/>
</component>
<component
name=
"Vcs.Log.Tabs.Properties"
>
...
...
@@ -84,6 +158,7 @@
<MESSAGE
value=
"first step"
/>
<MESSAGE
value=
"second step"
/>
<MESSAGE
value=
"third step"
/>
<option
name=
"LAST_COMMIT_MESSAGE"
value=
"third step"
/>
<MESSAGE
value=
"fourth step with main tester"
/>
<option
name=
"LAST_COMMIT_MESSAGE"
value=
"fourth step with main tester"
/>
</component>
</project>
\ No newline at end of file
src/test/java/ParallelSummersTest.java
0 → 100644
View file @
a7f4030f
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.*;
import
org.example.SequentialSummer
;
import
org.junit.jupiter.api.BeforeAll
;
import
org.junit.jupiter.api.Test
;
import
org.example.data.TestData
;
import
org.example.parallelsummers.ParallelSummer0
;
import
org.example.parallelsummers.ParallelSummer1
;
import
org.example.parallelsummers.ParallelSummer2
;
import
org.example.parallelsummers.ParallelSummer3
;
import
org.example.parallelsummers.ParallelSummer4
;
import
java.util.Arrays
;
import
java.util.List
;
class
ParallelSummersTest
{
/*
The ParallelSummersTest class is designed to assess the performance of other classes
that compute the count of prime numbers within a specified range.
The range starts from a variable named start and ends at a variable named end.
The data array contains the numbers within this range,
and the result variable stores the count of prime numbers calculated sequentially
*/
private
static
int
start
;
private
static
int
end
;
private
static
int
[]
data
;
private
static
long
result
;
/*
The function initialize is designed to identify the range and sequentially compute the result.
*/
@BeforeAll
public
static
void
initialize
()
{
start
=
0
;
end
=
20
;
data
=
TestData
.
createData
(
start
,
end
);
result
=
SequentialSummer
.
sum
(
SequentialSummer
.
allPrimes
(
data
));
}
/*
The testAll function is designed to compare the results of calculating the number of primes with five different parallel methods.
Each method requires a data array that contains a range of numbers and the number of threads to be used.
*/
private
static
void
testAll
(
int
threadCount
)
{
assertEquals
(
result
,
ParallelSummer0
.
sum
(
data
,
threadCount
));
assertEquals
(
result
,
ParallelSummer1
.
sum
(
data
,
threadCount
));
assertEquals
(
result
,
ParallelSummer2
.
sum
(
data
,
threadCount
));
assertEquals
(
result
,
ParallelSummer3
.
sum
(
data
,
threadCount
));
assertEquals
(
result
,
ParallelSummer4
.
sum
(
data
,
threadCount
));
System
.
out
.
println
(
result
);
}
/*
Invoke the testSingleThread function to call the testAll function using a single thread,
and then print the total duration in seconds it takes to execute the tasks in parallel.
*/
@Test
void
testSingleThread
()
{
long
start
=
System
.
currentTimeMillis
();
testAll
(
1
);
long
end
=
System
.
currentTimeMillis
();
System
.
out
.
println
(
"1 Thread takes "
+
(
end
-
start
)/
1000
+
" seconds"
);
}
/*
Invoke the testTwoThread function to call the testAll function using two threads,
and then print the total duration in seconds it takes to execute the tasks in parallel.
*/
@Test
void
testTwoThread
()
{
long
start
=
System
.
currentTimeMillis
();
testAll
(
2
);
long
end
=
System
.
currentTimeMillis
();
System
.
out
.
println
(
"2 Threads take "
+
(
end
-
start
)/
1000
+
" seconds"
);
}
/*
Invoke the testFourThread function to call the testAll function using four threads,
and then print the total duration in seconds it takes to execute the tasks in parallel.
*/
@Test
void
testFourThread
()
{
long
start
=
System
.
currentTimeMillis
();
testAll
(
4
);
long
end
=
System
.
currentTimeMillis
();
System
.
out
.
println
(
"4 Threads take "
+
(
end
-
start
)/
1000
+
" seconds"
);
}
/*
Invoke the testEightThread function to call the testAll function using eight threads,
and then print the total duration in seconds it takes to execute the tasks in parallel.
*/
@Test
void
testEightThread
()
{
long
start
=
System
.
currentTimeMillis
();
testAll
(
8
);
long
end
=
System
.
currentTimeMillis
();
System
.
out
.
println
(
"8 Threads take "
+
(
end
-
start
)/
1000
+
" seconds"
);
}
/*
Invoke the testSixteenThread function to call the testAll function using sixteen threads,
and then print the total duration in seconds it takes to execute the tasks in parallel.
*/
@Test
void
testSixteenThread
()
{
long
start
=
System
.
currentTimeMillis
();
testAll
(
16
);
long
end
=
System
.
currentTimeMillis
();
System
.
out
.
println
(
"16 Threads take "
+
(
end
-
start
)/
1000
+
" seconds"
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment