Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
91fe68a6
Commit
91fe68a6
authored
Apr 03, 2018
by
Shinya Maeda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use bytesize everywhere instead of length
parent
098fbac1
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
140 additions
and
1243 deletions
+140
-1243
lib/gitlab/ci/trace.rb
lib/gitlab/ci/trace.rb
+1
-1
lib/gitlab/ci/trace/chunked_file/chunk_store/database.rb
lib/gitlab/ci/trace/chunked_file/chunk_store/database.rb
+5
-5
lib/gitlab/ci/trace/chunked_file/chunk_store/redis.rb
lib/gitlab/ci/trace/chunked_file/chunk_store/redis.rb
+3
-3
lib/gitlab/ci/trace/chunked_file/chunked_io.rb
lib/gitlab/ci/trace/chunked_file/chunked_io.rb
+36
-18
lib/gitlab/ci/trace/chunked_file/concerns/errors.rb
lib/gitlab/ci/trace/chunked_file/concerns/errors.rb
+1
-0
spec/fixtures/trace/sample_trace
spec/fixtures/trace/sample_trace
+61
-1183
spec/lib/gitlab/ci/trace/chunked_file/live_trace_spec.rb
spec/lib/gitlab/ci/trace/chunked_file/live_trace_spec.rb
+1
-1
spec/support/shared_examples/lib/gitlab/ci/trace/chunked_file/chunked_io_shared_examples.rb
...itlab/ci/trace/chunked_file/chunked_io_shared_examples.rb
+32
-32
No files found.
lib/gitlab/ci/trace.rb
View file @
91fe68a6
...
@@ -77,7 +77,7 @@ module Gitlab
...
@@ -77,7 +77,7 @@ module Gitlab
def
write
def
write
stream
=
Gitlab
::
Ci
::
Trace
::
Stream
.
new
do
stream
=
Gitlab
::
Ci
::
Trace
::
Stream
.
new
do
if
Feature
.
enabled?
(
'ci_enable_live_trace'
)
if
Feature
.
enabled?
(
'ci_enable_live_trace'
)
||
true
if
current_path
if
current_path
current_path
current_path
else
else
...
...
lib/gitlab/ci/trace/chunked_file/chunk_store/database.rb
View file @
91fe68a6
...
@@ -27,7 +27,7 @@ module Gitlab
...
@@ -27,7 +27,7 @@ module Gitlab
def
chunks_size
(
job_id
)
def
chunks_size
(
job_id
)
::
Ci
::
JobTraceChunk
.
where
(
job_id:
job_id
).
pluck
(
'data'
)
::
Ci
::
JobTraceChunk
.
where
(
job_id:
job_id
).
pluck
(
'data'
)
.
inject
(
0
)
{
|
sum
,
data
|
sum
+
data
.
length
}
.
inject
(
0
)
{
|
sum
,
data
|
sum
+
data
.
bytesize
}
end
end
def
delete_all
(
job_id
)
def
delete_all
(
job_id
)
...
@@ -54,19 +54,19 @@ module Gitlab
...
@@ -54,19 +54,19 @@ module Gitlab
end
end
def
size
def
size
job_trace_chunk
.
data
&
.
length
||
0
job_trace_chunk
.
data
&
.
bytesize
||
0
end
end
def
write!
(
data
)
def
write!
(
data
)
raise
NotImplementedError
,
'Partial writing is not supported'
unless
params
[
:buffer_size
]
==
data
&
.
length
raise
NotImplementedError
,
'Partial writing is not supported'
unless
params
[
:buffer_size
]
==
data
&
.
bytesize
raise
NotImplementedError
,
'UPDATE (Overwriting data) is not supported'
if
job_trace_chunk
.
data
raise
NotImplementedError
,
'UPDATE (Overwriting data) is not supported'
if
job_trace_chunk
.
data
puts
"
#{
self
.
class
.
name
}
-
#{
__callee__
}
: data.
length:
#{
data
.
length
.
inspect
}
params[:chunk_index]:
#{
params
[
:chunk_index
]
}
"
puts
"
#{
self
.
class
.
name
}
-
#{
__callee__
}
: data.
bytesize:
#{
data
.
bytesize
.
inspect
}
params[:chunk_index]:
#{
params
[
:chunk_index
]
}
"
job_trace_chunk
.
data
=
data
job_trace_chunk
.
data
=
data
job_trace_chunk
.
save!
job_trace_chunk
.
save!
data
.
length
data
.
bytesize
end
end
def
append!
(
data
)
def
append!
(
data
)
...
...
lib/gitlab/ci/trace/chunked_file/chunk_store/redis.rb
View file @
91fe68a6
...
@@ -83,7 +83,7 @@ module Gitlab
...
@@ -83,7 +83,7 @@ module Gitlab
def
write!
(
data
)
def
write!
(
data
)
raise
ArgumentError
,
'Could not write empty data'
unless
data
.
present?
raise
ArgumentError
,
'Could not write empty data'
unless
data
.
present?
puts
"
#{
self
.
class
.
name
}
-
#{
__callee__
}
: data.
length:
#{
data
.
length
.
inspect
}
params[:chunk_index]:
#{
params
[
:chunk_index
]
}
"
puts
"
#{
self
.
class
.
name
}
-
#{
__callee__
}
: data.
bytesize:
#{
data
.
bytesize
.
inspect
}
params[:chunk_index]:
#{
params
[
:chunk_index
]
}
"
Gitlab
::
Redis
::
Cache
.
with
do
|
redis
|
Gitlab
::
Redis
::
Cache
.
with
do
|
redis
|
unless
redis
.
set
(
buffer_key
,
data
)
==
'OK'
unless
redis
.
set
(
buffer_key
,
data
)
==
'OK'
raise
WriteError
,
'Failed to write'
raise
WriteError
,
'Failed to write'
...
@@ -96,7 +96,7 @@ module Gitlab
...
@@ -96,7 +96,7 @@ module Gitlab
def
append!
(
data
)
def
append!
(
data
)
raise
ArgumentError
,
'Could not write empty data'
unless
data
.
present?
raise
ArgumentError
,
'Could not write empty data'
unless
data
.
present?
puts
"
#{
self
.
class
.
name
}
-
#{
__callee__
}
: data.
length:
#{
data
.
length
.
inspect
}
params[:chunk_index]:
#{
params
[
:chunk_index
]
}
"
puts
"
#{
self
.
class
.
name
}
-
#{
__callee__
}
: data.
bytesize:
#{
data
.
bytesize
.
inspect
}
params[:chunk_index]:
#{
params
[
:chunk_index
]
}
"
Gitlab
::
Redis
::
Cache
.
with
do
|
redis
|
Gitlab
::
Redis
::
Cache
.
with
do
|
redis
|
raise
BufferKeyNotFoundError
,
'Buffer key is not found'
unless
redis
.
exists
(
buffer_key
)
raise
BufferKeyNotFoundError
,
'Buffer key is not found'
unless
redis
.
exists
(
buffer_key
)
...
@@ -104,7 +104,7 @@ module Gitlab
...
@@ -104,7 +104,7 @@ module Gitlab
new_size
=
redis
.
append
(
buffer_key
,
data
)
new_size
=
redis
.
append
(
buffer_key
,
data
)
appended_size
=
new_size
-
original_size
appended_size
=
new_size
-
original_size
raise
WriteError
,
'Failed to append'
unless
appended_size
==
data
.
length
raise
WriteError
,
'Failed to append'
unless
appended_size
==
data
.
bytesize
appended_size
appended_size
end
end
...
...
lib/gitlab/ci/trace/chunked_file/chunked_io.rb
View file @
91fe68a6
...
@@ -84,7 +84,7 @@ module Gitlab
...
@@ -84,7 +84,7 @@ module Gitlab
def
read
(
length
=
nil
,
outbuf
=
nil
)
def
read
(
length
=
nil
,
outbuf
=
nil
)
out
=
""
out
=
""
until
eof?
||
(
length
&&
out
.
length
>=
length
)
until
eof?
||
(
length
&&
out
.
bytesize
>=
length
)
data
=
get_chunk
data
=
get_chunk
break
if
data
.
empty?
break
if
data
.
empty?
...
@@ -92,7 +92,7 @@ module Gitlab
...
@@ -92,7 +92,7 @@ module Gitlab
@tell
+=
data
.
bytesize
@tell
+=
data
.
bytesize
end
end
out
=
out
[
0
,
length
]
if
length
&&
out
.
length
>
length
out
=
out
.
byteslice
(
0
,
length
)
if
length
&&
out
.
bytesize
>
length
out
out
end
end
...
@@ -104,15 +104,15 @@ module Gitlab
...
@@ -104,15 +104,15 @@ module Gitlab
data
=
get_chunk
data
=
get_chunk
break
if
data
.
empty?
break
if
data
.
empty?
new_line
=
data
.
index
(
"
\n
"
)
new_line
_pos
=
byte_position
(
data
,
"
\n
"
)
if
!
new_line
.
nil?
if
new_line_pos
.
nil?
out
<<
data
[
0
..
new_line
]
@tell
+=
new_line
+
1
break
else
out
<<
data
out
<<
data
@tell
+=
data
.
bytesize
@tell
+=
data
.
bytesize
else
out
<<
data
.
byteslice
(
0
..
new_line_pos
)
@tell
+=
new_line_pos
+
1
break
end
end
end
end
...
@@ -123,7 +123,7 @@ module Gitlab
...
@@ -123,7 +123,7 @@ module Gitlab
raise
ArgumentError
,
'Could not write empty data'
unless
data
.
present?
raise
ArgumentError
,
'Could not write empty data'
unless
data
.
present?
if
mode
.
include?
(
'w'
)
if
mode
.
include?
(
'w'
)
write_as_overwrite
(
data
)
raise
NotImplementedError
,
"Overwrite is not supported"
elsif
mode
.
include?
(
'a'
)
elsif
mode
.
include?
(
'a'
)
write_as_append
(
data
)
write_as_append
(
data
)
end
end
...
@@ -157,27 +157,26 @@ module Gitlab
...
@@ -157,27 +157,26 @@ module Gitlab
unless
in_range?
unless
in_range?
chunk_store
.
open
(
job_id
,
chunk_index
,
params_for_store
)
do
|
store
|
chunk_store
.
open
(
job_id
,
chunk_index
,
params_for_store
)
do
|
store
|
@chunk
=
store
.
get
@chunk
=
store
.
get
@chunk_range
=
(
chunk_start
...
(
chunk_start
+
chunk
.
length
))
end
end
@chunk
[
chunk_offset
..
buffer_size
]
raise
ReadError
,
'Could not get a chunk'
unless
chunk
&&
chunk
.
present?
@chunk_range
=
(
chunk_start
...
(
chunk_start
+
chunk
.
bytesize
))
end
end
end
def
write_as_overwrite
(
data
)
@chunk
.
byteslice
(
chunk_offset
,
buffer_size
)
raise
NotImplementedError
,
"Overwrite is not supported"
end
end
def
write_as_append
(
data
)
def
write_as_append
(
data
)
@tell
=
size
@tell
=
size
data_size
=
data
.
size
data_size
=
data
.
byte
size
new_tell
=
tell
+
data_size
new_tell
=
tell
+
data_size
data_offset
=
0
data_offset
=
0
until
tell
==
new_tell
until
tell
==
new_tell
writable_size
=
buffer_size
-
chunk_offset
writable_size
=
buffer_size
-
chunk_offset
writable_data
=
data
[
data_offset
...
(
data_offset
+
writable_size
)]
writable_data
=
data
.
byteslice
(
data_offset
,
writable_size
)
written_size
=
write_chunk
(
writable_data
)
written_size
=
write_chunk
(
writable_data
)
data_offset
+=
written_size
data_offset
+=
written_size
...
@@ -199,7 +198,7 @@ module Gitlab
...
@@ -199,7 +198,7 @@ module Gitlab
store
.
write!
(
data
)
store
.
write!
(
data
)
end
end
raise
WriteError
,
'Written size mismatch'
unless
data
.
length
==
written_size
raise
WriteError
,
'Written size mismatch'
unless
data
.
bytesize
==
written_size
end
end
end
end
...
@@ -249,6 +248,25 @@ module Gitlab
...
@@ -249,6 +248,25 @@ module Gitlab
def
calculate_size
(
job_id
)
def
calculate_size
(
job_id
)
chunk_store
.
chunks_size
(
job_id
)
chunk_store
.
chunks_size
(
job_id
)
end
end
def
byte_position
(
data
,
pattern_byte
)
index_as_string
=
data
.
index
(
pattern_byte
)
return
nil
unless
index_as_string
if
data
.
getbyte
(
index_as_string
)
==
pattern_byte
.
getbyte
(
0
)
index_as_string
else
data2
=
data
.
byteslice
(
index_as_string
,
100
)
additional_pos
=
0
data2
.
each_byte
do
|
b
|
break
if
b
==
pattern_byte
.
getbyte
(
0
)
additional_pos
+=
1
end
index_as_string
+
additional_pos
end
end
end
end
end
end
end
end
...
...
lib/gitlab/ci/trace/chunked_file/concerns/errors.rb
View file @
91fe68a6
...
@@ -8,6 +8,7 @@ module Gitlab
...
@@ -8,6 +8,7 @@ module Gitlab
included
do
included
do
WriteError
=
Class
.
new
(
StandardError
)
WriteError
=
Class
.
new
(
StandardError
)
ReadError
=
Class
.
new
(
StandardError
)
end
end
end
end
end
end
...
...
spec/fixtures/trace/sample_trace
View file @
91fe68a6
This source diff could not be displayed because it is too large. You can
view the blob
instead.
spec/lib/gitlab/ci/trace/chunked_file/live_trace_spec.rb
View file @
91fe68a6
...
@@ -51,7 +51,7 @@ describe Gitlab::Ci::Trace::ChunkedFile::LiveTrace, :clean_gitlab_redis_cache do
...
@@ -51,7 +51,7 @@ describe Gitlab::Ci::Trace::ChunkedFile::LiveTrace, :clean_gitlab_redis_cache do
end
end
context
'when offset is size'
do
context
'when offset is size'
do
let
(
:offset
)
{
sample_trace_raw
.
length
}
let
(
:offset
)
{
sample_trace_raw
.
bytesize
}
it
'does nothing'
do
it
'does nothing'
do
expect
{
subject
}.
not_to
change
{
described_class
.
exist?
(
job_id
)
}
expect
{
subject
}.
not_to
change
{
described_class
.
exist?
(
job_id
)
}
...
...
spec/support/shared_examples/lib/gitlab/ci/trace/chunked_file/chunked_io_shared_examples.rb
View file @
91fe68a6
...
@@ -90,7 +90,7 @@ shared_examples "ChunkedIO shared tests" do
...
@@ -90,7 +90,7 @@ shared_examples "ChunkedIO shared tests" do
subject
{
chunked_io
.
seek
(
pos
,
where
)
}
subject
{
chunked_io
.
seek
(
pos
,
where
)
}
before
do
before
do
set_smaller_buffer_size_than
(
sample_trace_raw
.
length
)
set_smaller_buffer_size_than
(
sample_trace_raw
.
bytesize
)
fill_trace_to_chunks
(
sample_trace_raw
)
fill_trace_to_chunks
(
sample_trace_raw
)
end
end
...
@@ -98,11 +98,11 @@ shared_examples "ChunkedIO shared tests" do
...
@@ -98,11 +98,11 @@ shared_examples "ChunkedIO shared tests" do
let
(
:pos
)
{
0
}
let
(
:pos
)
{
0
}
let
(
:where
)
{
IO
::
SEEK_END
}
let
(
:where
)
{
IO
::
SEEK_END
}
it
{
is_expected
.
to
eq
(
sample_trace_raw
.
length
)
}
it
{
is_expected
.
to
eq
(
sample_trace_raw
.
bytesize
)
}
end
end
context
'when moves pos to middle of the file'
do
context
'when moves pos to middle of the file'
do
let
(
:pos
)
{
sample_trace_raw
.
length
/
2
}
let
(
:pos
)
{
sample_trace_raw
.
bytesize
/
2
}
let
(
:where
)
{
IO
::
SEEK_SET
}
let
(
:where
)
{
IO
::
SEEK_SET
}
it
{
is_expected
.
to
eq
(
pos
)
}
it
{
is_expected
.
to
eq
(
pos
)
}
...
@@ -112,7 +112,7 @@ shared_examples "ChunkedIO shared tests" do
...
@@ -112,7 +112,7 @@ shared_examples "ChunkedIO shared tests" do
it
'matches the result'
do
it
'matches the result'
do
expect
(
chunked_io
.
seek
(
0
)).
to
eq
(
0
)
expect
(
chunked_io
.
seek
(
0
)).
to
eq
(
0
)
expect
(
chunked_io
.
seek
(
100
,
IO
::
SEEK_CUR
)).
to
eq
(
100
)
expect
(
chunked_io
.
seek
(
100
,
IO
::
SEEK_CUR
)).
to
eq
(
100
)
expect
{
chunked_io
.
seek
(
sample_trace_raw
.
length
+
1
,
IO
::
SEEK_CUR
)
}
expect
{
chunked_io
.
seek
(
sample_trace_raw
.
bytesize
+
1
,
IO
::
SEEK_CUR
)
}
.
to
raise_error
(
'new position is outside of file'
)
.
to
raise_error
(
'new position is outside of file'
)
end
end
end
end
...
@@ -122,13 +122,13 @@ shared_examples "ChunkedIO shared tests" do
...
@@ -122,13 +122,13 @@ shared_examples "ChunkedIO shared tests" do
subject
{
chunked_io
.
eof?
}
subject
{
chunked_io
.
eof?
}
before
do
before
do
set_smaller_buffer_size_than
(
sample_trace_raw
.
length
)
set_smaller_buffer_size_than
(
sample_trace_raw
.
bytesize
)
fill_trace_to_chunks
(
sample_trace_raw
)
fill_trace_to_chunks
(
sample_trace_raw
)
end
end
context
'when current pos is at end of the file'
do
context
'when current pos is at end of the file'
do
before
do
before
do
chunked_io
.
seek
(
sample_trace_raw
.
length
,
IO
::
SEEK_SET
)
chunked_io
.
seek
(
sample_trace_raw
.
bytesize
,
IO
::
SEEK_SET
)
end
end
it
{
is_expected
.
to
be_truthy
}
it
{
is_expected
.
to
be_truthy
}
...
@@ -148,7 +148,7 @@ shared_examples "ChunkedIO shared tests" do
...
@@ -148,7 +148,7 @@ shared_examples "ChunkedIO shared tests" do
context
'when buffer size is smaller than file size'
do
context
'when buffer size is smaller than file size'
do
before
do
before
do
set_smaller_buffer_size_than
(
sample_trace_raw
.
length
)
set_smaller_buffer_size_than
(
sample_trace_raw
.
bytesize
)
fill_trace_to_chunks
(
sample_trace_raw
)
fill_trace_to_chunks
(
sample_trace_raw
)
end
end
...
@@ -160,7 +160,7 @@ shared_examples "ChunkedIO shared tests" do
...
@@ -160,7 +160,7 @@ shared_examples "ChunkedIO shared tests" do
context
'when buffer size is larger than file size'
,
:partial_support
do
context
'when buffer size is larger than file size'
,
:partial_support
do
before
do
before
do
set_larger_buffer_size_than
(
sample_trace_raw
.
length
)
set_larger_buffer_size_than
(
sample_trace_raw
.
bytesize
)
fill_trace_to_chunks
(
sample_trace_raw
)
fill_trace_to_chunks
(
sample_trace_raw
)
end
end
...
@@ -186,7 +186,7 @@ shared_examples "ChunkedIO shared tests" do
...
@@ -186,7 +186,7 @@ shared_examples "ChunkedIO shared tests" do
context
'when buffer size is smaller than file size'
do
context
'when buffer size is smaller than file size'
do
before
do
before
do
set_smaller_buffer_size_than
(
sample_trace_raw
.
length
)
set_smaller_buffer_size_than
(
sample_trace_raw
.
bytesize
)
fill_trace_to_chunks
(
sample_trace_raw
)
fill_trace_to_chunks
(
sample_trace_raw
)
end
end
...
@@ -195,7 +195,7 @@ shared_examples "ChunkedIO shared tests" do
...
@@ -195,7 +195,7 @@ shared_examples "ChunkedIO shared tests" do
context
'when buffer size is larger than file size'
,
:partial_support
do
context
'when buffer size is larger than file size'
,
:partial_support
do
before
do
before
do
set_larger_buffer_size_than
(
sample_trace_raw
.
length
)
set_larger_buffer_size_than
(
sample_trace_raw
.
bytesize
)
fill_trace_to_chunks
(
sample_trace_raw
)
fill_trace_to_chunks
(
sample_trace_raw
)
end
end
...
@@ -204,7 +204,7 @@ shared_examples "ChunkedIO shared tests" do
...
@@ -204,7 +204,7 @@ shared_examples "ChunkedIO shared tests" do
context
'when buffer size is half of file size'
do
context
'when buffer size is half of file size'
do
before
do
before
do
set_half_buffer_size_of
(
sample_trace_raw
.
length
)
set_half_buffer_size_of
(
sample_trace_raw
.
bytesize
)
fill_trace_to_chunks
(
sample_trace_raw
)
fill_trace_to_chunks
(
sample_trace_raw
)
end
end
...
@@ -217,7 +217,7 @@ shared_examples "ChunkedIO shared tests" do
...
@@ -217,7 +217,7 @@ shared_examples "ChunkedIO shared tests" do
context
'when buffer size is smaller than file size'
do
context
'when buffer size is smaller than file size'
do
before
do
before
do
set_smaller_buffer_size_than
(
sample_trace_raw
.
length
)
set_smaller_buffer_size_than
(
sample_trace_raw
.
bytesize
)
fill_trace_to_chunks
(
sample_trace_raw
)
fill_trace_to_chunks
(
sample_trace_raw
)
end
end
...
@@ -228,7 +228,7 @@ shared_examples "ChunkedIO shared tests" do
...
@@ -228,7 +228,7 @@ shared_examples "ChunkedIO shared tests" do
context
'when buffer size is larger than file size'
,
:partial_support
do
context
'when buffer size is larger than file size'
,
:partial_support
do
before
do
before
do
set_larger_buffer_size_than
(
sample_trace_raw
.
length
)
set_larger_buffer_size_than
(
sample_trace_raw
.
bytesize
)
fill_trace_to_chunks
(
sample_trace_raw
)
fill_trace_to_chunks
(
sample_trace_raw
)
end
end
...
@@ -239,11 +239,11 @@ shared_examples "ChunkedIO shared tests" do
...
@@ -239,11 +239,11 @@ shared_examples "ChunkedIO shared tests" do
end
end
context
'when tries to read oversize'
do
context
'when tries to read oversize'
do
let
(
:length
)
{
sample_trace_raw
.
length
+
1000
}
let
(
:length
)
{
sample_trace_raw
.
bytesize
+
1000
}
context
'when buffer size is smaller than file size'
do
context
'when buffer size is smaller than file size'
do
before
do
before
do
set_smaller_buffer_size_than
(
sample_trace_raw
.
length
)
set_smaller_buffer_size_than
(
sample_trace_raw
.
bytesize
)
fill_trace_to_chunks
(
sample_trace_raw
)
fill_trace_to_chunks
(
sample_trace_raw
)
end
end
...
@@ -254,7 +254,7 @@ shared_examples "ChunkedIO shared tests" do
...
@@ -254,7 +254,7 @@ shared_examples "ChunkedIO shared tests" do
context
'when buffer size is larger than file size'
,
:partial_support
do
context
'when buffer size is larger than file size'
,
:partial_support
do
before
do
before
do
set_larger_buffer_size_than
(
sample_trace_raw
.
length
)
set_larger_buffer_size_than
(
sample_trace_raw
.
bytesize
)
fill_trace_to_chunks
(
sample_trace_raw
)
fill_trace_to_chunks
(
sample_trace_raw
)
end
end
...
@@ -269,7 +269,7 @@ shared_examples "ChunkedIO shared tests" do
...
@@ -269,7 +269,7 @@ shared_examples "ChunkedIO shared tests" do
context
'when buffer size is smaller than file size'
do
context
'when buffer size is smaller than file size'
do
before
do
before
do
set_smaller_buffer_size_than
(
sample_trace_raw
.
length
)
set_smaller_buffer_size_than
(
sample_trace_raw
.
bytesize
)
fill_trace_to_chunks
(
sample_trace_raw
)
fill_trace_to_chunks
(
sample_trace_raw
)
end
end
...
@@ -280,7 +280,7 @@ shared_examples "ChunkedIO shared tests" do
...
@@ -280,7 +280,7 @@ shared_examples "ChunkedIO shared tests" do
context
'when buffer size is larger than file size'
,
:partial_support
do
context
'when buffer size is larger than file size'
,
:partial_support
do
before
do
before
do
set_larger_buffer_size_than
(
sample_trace_raw
.
length
)
set_larger_buffer_size_than
(
sample_trace_raw
.
bytesize
)
fill_trace_to_chunks
(
sample_trace_raw
)
fill_trace_to_chunks
(
sample_trace_raw
)
end
end
...
@@ -306,7 +306,7 @@ shared_examples "ChunkedIO shared tests" do
...
@@ -306,7 +306,7 @@ shared_examples "ChunkedIO shared tests" do
context
'when buffer size is smaller than file size'
do
context
'when buffer size is smaller than file size'
do
before
do
before
do
set_smaller_buffer_size_than
(
sample_trace_raw
.
length
)
set_smaller_buffer_size_than
(
sample_trace_raw
.
bytesize
)
fill_trace_to_chunks
(
sample_trace_raw
)
fill_trace_to_chunks
(
sample_trace_raw
)
end
end
...
@@ -315,7 +315,7 @@ shared_examples "ChunkedIO shared tests" do
...
@@ -315,7 +315,7 @@ shared_examples "ChunkedIO shared tests" do
context
'when buffer size is larger than file size'
,
:partial_support
do
context
'when buffer size is larger than file size'
,
:partial_support
do
before
do
before
do
set_larger_buffer_size_than
(
sample_trace_raw
.
length
)
set_larger_buffer_size_than
(
sample_trace_raw
.
bytesize
)
fill_trace_to_chunks
(
sample_trace_raw
)
fill_trace_to_chunks
(
sample_trace_raw
)
end
end
...
@@ -324,7 +324,7 @@ shared_examples "ChunkedIO shared tests" do
...
@@ -324,7 +324,7 @@ shared_examples "ChunkedIO shared tests" do
context
'when buffer size is half of file size'
do
context
'when buffer size is half of file size'
do
before
do
before
do
set_half_buffer_size_of
(
sample_trace_raw
.
length
)
set_half_buffer_size_of
(
sample_trace_raw
.
bytesize
)
fill_trace_to_chunks
(
sample_trace_raw
)
fill_trace_to_chunks
(
sample_trace_raw
)
end
end
...
@@ -333,7 +333,7 @@ shared_examples "ChunkedIO shared tests" do
...
@@ -333,7 +333,7 @@ shared_examples "ChunkedIO shared tests" do
context
'when pos is at middle of the file'
do
context
'when pos is at middle of the file'
do
before
do
before
do
set_smaller_buffer_size_than
(
sample_trace_raw
.
length
)
set_smaller_buffer_size_than
(
sample_trace_raw
.
bytesize
)
fill_trace_to_chunks
(
sample_trace_raw
)
fill_trace_to_chunks
(
sample_trace_raw
)
chunked_io
.
seek
(
chunked_io
.
size
/
2
)
chunked_io
.
seek
(
chunked_io
.
size
/
2
)
...
@@ -357,21 +357,21 @@ shared_examples "ChunkedIO shared tests" do
...
@@ -357,21 +357,21 @@ shared_examples "ChunkedIO shared tests" do
context
'when data does not exist'
do
context
'when data does not exist'
do
shared_examples
'writes a trace'
do
shared_examples
'writes a trace'
do
it
do
it
do
is_expected
.
to
eq
(
data
.
length
)
is_expected
.
to
eq
(
data
.
bytesize
)
described_class
.
new
(
job_id
,
nil
,
'rb'
)
do
|
stream
|
described_class
.
new
(
job_id
,
nil
,
'rb'
)
do
|
stream
|
expect
(
stream
.
read
).
to
eq
(
data
)
expect
(
stream
.
read
).
to
eq
(
data
)
expect
(
chunk_stores
.
inject
(
0
)
{
|
sum
,
store
|
sum
+
store
.
chunks_count
(
job_id
)
})
expect
(
chunk_stores
.
inject
(
0
)
{
|
sum
,
store
|
sum
+
store
.
chunks_count
(
job_id
)
})
.
to
eq
(
stream
.
send
(
:chunks_count
))
.
to
eq
(
stream
.
send
(
:chunks_count
))
expect
(
chunk_stores
.
inject
(
0
)
{
|
sum
,
store
|
sum
+
store
.
chunks_size
(
job_id
)
})
expect
(
chunk_stores
.
inject
(
0
)
{
|
sum
,
store
|
sum
+
store
.
chunks_size
(
job_id
)
})
.
to
eq
(
data
.
length
)
.
to
eq
(
data
.
bytesize
)
end
end
end
end
end
end
context
'when buffer size is smaller than file size'
do
context
'when buffer size is smaller than file size'
do
before
do
before
do
set_smaller_buffer_size_than
(
data
.
length
)
set_smaller_buffer_size_than
(
data
.
bytesize
)
end
end
it_behaves_like
'writes a trace'
it_behaves_like
'writes a trace'
...
@@ -379,7 +379,7 @@ shared_examples "ChunkedIO shared tests" do
...
@@ -379,7 +379,7 @@ shared_examples "ChunkedIO shared tests" do
context
'when buffer size is larger than file size'
,
:partial_support
do
context
'when buffer size is larger than file size'
,
:partial_support
do
before
do
before
do
set_larger_buffer_size_than
(
data
.
length
)
set_larger_buffer_size_than
(
data
.
bytesize
)
end
end
it_behaves_like
'writes a trace'
it_behaves_like
'writes a trace'
...
@@ -387,7 +387,7 @@ shared_examples "ChunkedIO shared tests" do
...
@@ -387,7 +387,7 @@ shared_examples "ChunkedIO shared tests" do
context
'when buffer size is half of file size'
do
context
'when buffer size is half of file size'
do
before
do
before
do
set_half_buffer_size_of
(
data
.
length
)
set_half_buffer_size_of
(
data
.
bytesize
)
end
end
it_behaves_like
'writes a trace'
it_behaves_like
'writes a trace'
...
@@ -404,12 +404,12 @@ shared_examples "ChunkedIO shared tests" do
...
@@ -404,12 +404,12 @@ shared_examples "ChunkedIO shared tests" do
context
'when data already exists'
,
:partial_support
do
context
'when data already exists'
,
:partial_support
do
let
(
:exist_data
)
{
'exist data'
}
let
(
:exist_data
)
{
'exist data'
}
let
(
:total_size
)
{
exist_data
.
length
+
data
.
length
}
let
(
:total_size
)
{
exist_data
.
bytesize
+
data
.
bytesize
}
shared_examples
'appends a trace'
do
shared_examples
'appends a trace'
do
it
do
it
do
described_class
.
new
(
job_id
,
nil
,
'a+b'
)
do
|
stream
|
described_class
.
new
(
job_id
,
nil
,
'a+b'
)
do
|
stream
|
expect
(
stream
.
write
(
data
)).
to
eq
(
data
.
length
)
expect
(
stream
.
write
(
data
)).
to
eq
(
data
.
bytesize
)
end
end
described_class
.
new
(
job_id
,
nil
,
'rb'
)
do
|
stream
|
described_class
.
new
(
job_id
,
nil
,
'rb'
)
do
|
stream
|
...
@@ -424,7 +424,7 @@ shared_examples "ChunkedIO shared tests" do
...
@@ -424,7 +424,7 @@ shared_examples "ChunkedIO shared tests" do
context
'when buffer size is smaller than file size'
do
context
'when buffer size is smaller than file size'
do
before
do
before
do
set_smaller_buffer_size_than
(
data
.
length
)
set_smaller_buffer_size_than
(
data
.
bytesize
)
fill_trace_to_chunks
(
exist_data
)
fill_trace_to_chunks
(
exist_data
)
end
end
...
@@ -433,7 +433,7 @@ shared_examples "ChunkedIO shared tests" do
...
@@ -433,7 +433,7 @@ shared_examples "ChunkedIO shared tests" do
context
'when buffer size is larger than file size'
,
:partial_support
do
context
'when buffer size is larger than file size'
,
:partial_support
do
before
do
before
do
set_larger_buffer_size_than
(
data
.
length
)
set_larger_buffer_size_than
(
data
.
bytesize
)
fill_trace_to_chunks
(
exist_data
)
fill_trace_to_chunks
(
exist_data
)
end
end
...
@@ -442,7 +442,7 @@ shared_examples "ChunkedIO shared tests" do
...
@@ -442,7 +442,7 @@ shared_examples "ChunkedIO shared tests" do
context
'when buffer size is half of file size'
do
context
'when buffer size is half of file size'
do
before
do
before
do
set_half_buffer_size_of
(
data
.
length
)
set_half_buffer_size_of
(
data
.
bytesize
)
fill_trace_to_chunks
(
exist_data
)
fill_trace_to_chunks
(
exist_data
)
end
end
...
...
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