Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
distributed systems cw
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ik1g19
distributed systems cw
Commits
c7e04386
Commit
c7e04386
authored
4 years ago
by
ik1g19
Browse files
Options
Downloads
Patches
Plain Diff
add test files
parent
1d351b77
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
AbstractTest.java
+43
-0
43 additions, 0 deletions
AbstractTest.java
FileCopyTest.java
+37
-0
37 additions, 0 deletions
FileCopyTest.java
with
80 additions
and
0 deletions
AbstractTest.java
0 → 100644
+
43
−
0
View file @
c7e04386
package
com.javacodegeeks.nio.large_file_transfer
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
java.io.File
;
import
java.io.IOException
;
import
java.nio.file.Files
;
import
org.junit.AfterClass
;
import
org.junit.Before
;
import
org.junit.BeforeClass
;
public
abstract
class
AbstractTest
{
protected
static
final
String
SRC
=
"/tmp/input.tar.gz"
;
protected
static
final
String
TARGET
=
"/tmp/output"
;
protected
static
final
long
AWAIT_TEST_COMPLETE
=
20000
l
;
protected
File
srcFile
;
protected
File
targetFile
;
@BeforeClass
public
static
void
init
()
{
Thread
.
currentThread
().
getContextClassLoader
().
setDefaultAssertionStatus
(
true
);
}
@AfterClass
public
static
void
destroy
()
{
Thread
.
currentThread
().
getContextClassLoader
().
setDefaultAssertionStatus
(
false
);
}
@Before
public
void
setUp
()
throws
IOException
{
this
.
srcFile
=
new
File
(
SRC
);
this
.
targetFile
=
new
File
(
TARGET
+
"/"
+
this
.
srcFile
.
getName
());
Files
.
deleteIfExists
(
this
.
targetFile
.
toPath
());
}
protected
final
void
compare
()
{
assertEquals
(
"file did not copy completely"
,
this
.
srcFile
.
length
(),
this
.
targetFile
.
length
());
}
}
This diff is collapsed.
Click to expand it.
FileCopyTest.java
0 → 100644
+
37
−
0
View file @
c7e04386
package
com.javacodegeeks.nio.large_file_transfer.remote
;
import
java.io.IOException
;
import
java.util.concurrent.CountDownLatch
;
import
org.junit.Test
;
import
com.javacodegeeks.nio.large_file_transfer.AbstractTest
;
public
class
FileCopyTest
extends
AbstractTest
{
private
static
final
int
PORT
=
9999
;
@Test
public
void
copyLargeFile
()
throws
IOException
,
InterruptedException
{
final
CountDownLatch
latch
=
new
CountDownLatch
(
1
);
final
FileReceiver
receiver
=
new
FileReceiver
(
PORT
,
new
FileWriter
(
TARGET
+
"/"
+
super
.
srcFile
.
getName
()),
super
.
srcFile
.
length
());
new
Thread
()
{
public
void
run
()
{
try
{
receiver
.
receive
();
}
catch
(
IOException
e
)
{
}
finally
{
latch
.
countDown
();
}
}
}.
start
();
final
FileReader
reader
=
new
FileReader
(
new
FileSender
(
PORT
),
SRC
);
reader
.
read
();
latch
.
await
();
compare
();
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment