Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
S3Zip
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Coscine
backend
scripts
S3Zip
Commits
ddf7ca8b
Commit
ddf7ca8b
authored
6 years ago
by
L. Ellenbeck
Browse files
Options
Downloads
Patches
Plain Diff
added unit test for S3MultipartStream coscine/issues#81
parent
31e2f179
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!2
Product/75 s3 zip metadata
,
!1
Topic/81 s3 zip upload
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/cs-S3Zip.Tests/S3ZipTests.cs
+72
-12
72 additions, 12 deletions
src/cs-S3Zip.Tests/S3ZipTests.cs
src/cs-S3Zip.Tests/cs-S3Zip.Tests.csproj
+1
-1
1 addition, 1 deletion
src/cs-S3Zip.Tests/cs-S3Zip.Tests.csproj
src/cs-S3Zip/S3MultipartStream.cs
+9
-4
9 additions, 4 deletions
src/cs-S3Zip/S3MultipartStream.cs
with
82 additions
and
17 deletions
src/cs-S3Zip.Tests/S3ZipTests.cs
+
72
−
12
View file @
ddf7ca8b
using
Amazon.S3
;
using
coscine.cs_S3Zip
;
using
Amazon.S3.Model
;
using
NUnit.Framework
;
using
System
;
using
System.IO
;
using
System.Linq
;
using
System.Security.Cryptography
;
namespace
cs_S3Zip.Tests
namespace
coscine.
cs_S3Zip.Tests
{
[
TestFixture
]
public
class
S3ZipTests
{
private
readonly
S3MultipartStreamConfiguration
_s3MultipartStreamConfiguration
;
private
readonly
int
ONE_MB
;
public
S3ZipTests
()
{
var
accessKey
=
Environment
.
GetEnvironmentVariable
(
"
AccessKey
"
,
EnvironmentVariableTarget
.
User
);
var
secretKey
=
Environment
.
GetEnvironmentVariable
(
"S
ecretKey
"
,
EnvironmentVariableTarget
.
User
);
var
accessKey
=
Environment
.
GetEnvironmentVariable
(
"
S3_ACCESS_KEY
"
,
EnvironmentVariableTarget
.
User
);
var
secretKey
=
Environment
.
GetEnvironmentVariable
(
"S
3_SECRET_KEY
"
,
EnvironmentVariableTarget
.
User
);
ONE_MB
=
(
int
)
Math
.
Pow
(
2
,
20
);
_s3MultipartStreamConfiguration
=
new
S3MultipartStreamConfiguration
{
...
...
@@ -31,18 +36,73 @@ namespace cs_S3Zip.Tests
};
}
[
Test
]
/*
[Test]
public void ZipAndUpload()
{
//
var s3 = new S3Zip(_s3MultipartStreamConfiguration);
//
s3.ZipAndUploadFolder(@"c:\temp\test", "zipTest4.zip");
var s3 = new S3Zip(_s3MultipartStreamConfiguration);
s3.ZipAndUploadFolder(@"c:\temp\test", "zipTest4.zip");
Assert.IsTrue(true);
}*/
[
TestCase
(
110
,
50
)]
[
TestCase
(
110
,
5
)]
[
TestCase
(
30
,
50
)]
[
TestCase
(
30
,
5
)]
public
void
S3StreamTest
(
int
length
,
int
chunkSize
)
{
var
key
=
"S3StreamTest.txt"
;
var
chars
=
"$%#@!*abcdefghijklmnopqrstuvwxyz1234567890?;:ABCDEFGHIJKLMNOPQRSTUVWXYZ^&"
.
ToCharArray
();
var
random
=
new
Random
();
var
randomArray
=
new
byte
[
length
*
ONE_MB
];
var
oldChunkSize
=
_s3MultipartStreamConfiguration
.
ChunckSize
;
_s3MultipartStreamConfiguration
.
ChunckSize
=
chunkSize
*
ONE_MB
;
// fill array with random data
for
(
int
i
=
0
;
i
<
randomArray
.
Length
;
i
++)
{
randomArray
[
i
]
=
(
byte
)
chars
[
random
.
Next
(
chars
.
Length
)];
}
[
Test
]
public
void
S3StreamTest
()
using
(
var
s3Stream
=
new
S3MultipartStream
(
key
,
_s3MultipartStreamConfiguration
))
{
Assert
.
IsTrue
(
true
);
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
s3Stream
.
Write
(
randomArray
,
i
*
ONE_MB
,
ONE_MB
);
}
}
var
request
=
new
GetObjectRequest
{
BucketName
=
_s3MultipartStreamConfiguration
.
BucketName
,
Key
=
key
};
using
(
var
client
=
new
AmazonS3Client
(
_s3MultipartStreamConfiguration
.
AccessKey
,
_s3MultipartStreamConfiguration
.
SecretKey
,
_s3MultipartStreamConfiguration
.
AmazonS3Config
))
{
var
buffer
=
new
byte
[
ONE_MB
];
using
(
var
response
=
client
.
GetObject
(
request
))
{
// Was request successfull?
Assert
.
IsTrue
(
response
.
HttpStatusCode
==
System
.
Net
.
HttpStatusCode
.
OK
);
// Has the correct length?
Assert
.
IsTrue
(
response
.
ContentLength
==
length
*
ONE_MB
);
using
(
var
responseStream
=
response
.
ResponseStream
)
{
int
alreadyRead
=
0
;
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
int
read
=
responseStream
.
Read
(
buffer
,
0
,
buffer
.
Length
);
// check if the data is equal to the previously generated one.
Assert
.
IsTrue
(
Enumerable
.
SequenceEqual
(
randomArray
.
Skip
(
alreadyRead
).
Take
(
read
),
buffer
.
Take
(
read
)));
alreadyRead
+=
read
;
}
}
}
}
_s3MultipartStreamConfiguration
.
ChunckSize
=
oldChunkSize
;
}
}
}
This diff is collapsed.
Click to expand it.
src/cs-S3Zip.Tests/cs-S3Zip.Tests.csproj
+
1
−
1
View file @
ddf7ca8b
...
...
@@ -9,7 +9,7 @@
<ProjectGuid>
{6B58EB5E-D857-464B-8174-C17375BAE1CF}
</ProjectGuid>
<OutputType>
Library
</OutputType>
<AppDesignerFolder>
Properties
</AppDesignerFolder>
<RootNamespace>
cs_S3Zip.Tests
</RootNamespace>
<RootNamespace>
coscine.
cs_S3Zip.Tests
</RootNamespace>
<AssemblyName>
cs-S3Zip.Tests
</AssemblyName>
<TargetFrameworkVersion>
v4.7.2
</TargetFrameworkVersion>
<FileAlignment>
512
</FileAlignment>
...
...
This diff is collapsed.
Click to expand it.
src/cs-S3Zip/S3MultipartStream.cs
+
9
−
4
View file @
ddf7ca8b
...
...
@@ -8,18 +8,18 @@ namespace coscine.cs_S3Zip
{
public
class
S3MultipartStream
:
Stream
{
private
Memory
Stream
_internalStream
;
private
readonly
Stream
_internalStream
;
private
readonly
InitiateMultipartUploadResponse
_initiateMultipartUploadResponse
;
private
readonly
List
<
UploadPartResponse
>
_uploadPartResponses
;
private
int
_part
;
private
int
_length
;
private
int
_position
;
public
S3MultipartStream
(
string
key
,
S3MultipartStreamConfiguration
s3MultipartStreamConfiguration
)
public
S3MultipartStream
(
string
key
,
S3MultipartStreamConfiguration
s3MultipartStreamConfiguration
,
Stream
internalStream
)
{
S3MultipartStreamConfiguration
=
s3MultipartStreamConfiguration
;
_internalStream
=
new
MemoryStream
(
S3MultipartStreamConfiguration
.
ChunckSize
)
;
_internalStream
=
internalStream
;
_uploadPartResponses
=
new
List
<
UploadPartResponse
>();
_part
=
0
;
_length
=
0
;
...
...
@@ -39,6 +39,11 @@ namespace coscine.cs_S3Zip
}
}
public
S3MultipartStream
(
string
key
,
S3MultipartStreamConfiguration
s3MultipartStreamConfiguration
)
:
this
(
key
,
s3MultipartStreamConfiguration
,
new
MemoryStream
(
s3MultipartStreamConfiguration
.
ChunckSize
))
{
}
public
string
Key
{
get
;
}
public
S3MultipartStreamConfiguration
S3MultipartStreamConfiguration
{
get
;
set
;
}
...
...
@@ -115,8 +120,8 @@ namespace coscine.cs_S3Zip
InputStream
=
_internalStream
};
_part
++;
_uploadPartResponses
.
Add
(
client
.
UploadPart
(
uploadPartRequest
));
_part
++;
}
}
...
...
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