Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
S
Synchronization_of_threads
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
yazan.halloul
Synchronization_of_threads
Commits
54a96b52
Commit
54a96b52
authored
Nov 28, 2023
by
yazan.halloul
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test Producer and Consumer classes
parent
9614576c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
0 deletions
+66
-0
ConsumerTest.java
src/test/java/ConsumerTest.java
+39
-0
ProducerTest.java
src/test/java/ProducerTest.java
+27
-0
No files found.
src/test/java/ConsumerTest.java
0 → 100644
View file @
54a96b52
import
junit.framework.TestCase
;
import
main_pipeline.Consumer
;
import
main_pipeline.Producer
;
import
benefit_classes.LineSequence
;
import
benefit_classes.LineSequenceComparator
;
import
java.io.BufferedReader
;
import
java.io.FileReader
;
import
java.io.IOException
;
import
java.util.concurrent.BlockingQueue
;
import
java.util.concurrent.LinkedBlockingQueue
;
import
java.util.concurrent.PriorityBlockingQueue
;
import
static
junit
.
framework
.
Assert
.
assertEquals
;
public
class
ConsumerTest
extends
TestCase
{
BlockingQueue
<
LineSequence
>
inputQueue
=
new
PriorityBlockingQueue
<>(
50
,
new
LineSequenceComparator
());
Consumer
consumer
=
new
Consumer
(
inputQueue
,
"C:\\Users\\dell\\Desktop\\Sequence text.txt"
);
public
void
testWriteToFile
()
throws
InterruptedException
{
inputQueue
.
put
(
new
LineSequence
(
"EOF"
,
3
));
inputQueue
.
put
(
new
LineSequence
(
"this is"
,
1
));
inputQueue
.
put
(
new
LineSequence
(
"test text"
,
2
));
consumer
.
run
();
try
(
BufferedReader
reader
=
new
BufferedReader
(
new
FileReader
(
"C:\\Users\\dell\\Desktop\\Sequence text.txt"
)))
{
String
line
;
String
allText
=
""
;
while
((
line
=
reader
.
readLine
())
!=
null
)
{
allText
+=
line
;
}
assertEquals
(
allText
,
"this istest text"
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
src/test/java/ProducerTest.java
0 → 100644
View file @
54a96b52
import
junit.framework.TestCase
;
import
main_pipeline.Producer
;
import
benefit_classes.LineSequence
;
import
java.util.concurrent.BlockingQueue
;
import
java.util.concurrent.LinkedBlockingQueue
;
public
class
ProducerTest
extends
TestCase
{
BlockingQueue
<
LineSequence
>
inputQueue
=
new
LinkedBlockingQueue
<>();
Producer
producer
=
new
Producer
(
inputQueue
,
"C:\\Users\\dell\\Desktop\\Test Text.txt"
);
BlockingQueue
<
LineSequence
>
actualQueue
=
new
LinkedBlockingQueue
<>();
public
void
testReadFile
()
{
producer
.
run
();
actualQueue
.
add
(
new
LineSequence
(
"this is"
,
1
));
actualQueue
.
add
(
new
LineSequence
(
"test text"
,
2
));
actualQueue
.
add
(
new
LineSequence
(
"EOF"
,
3
));
for
(
int
i
=
0
;
i
<
actualQueue
.
size
();
i
++)
{
assertEquals
(
inputQueue
.
peek
().
getLine
(),
actualQueue
.
peek
().
getLine
());
assertEquals
(
inputQueue
.
peek
().
getSequence
(),
actualQueue
.
peek
().
getSequence
());
inputQueue
.
remove
();
actualQueue
.
remove
();
}
}
}
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