RUMM-2767 Add the 'forceNewBatch' option into the FeatureScope#1174
Conversation
de732cb to
404b92a
Compare
404b92a to
06b450a
Compare
| return reusableFile ?: createNewFile() | ||
| } | ||
|
|
||
| override fun getNewWritableFile(): File? { |
There was a problem hiding this comment.
instead of making a new method that is almost identical to getWritableFile you could instead do
@WorkerThread
override fun getWritableFile(forceNewFile: Boolean = false): File? {
if (!isRootDirValid()) {
return null
}
deleteObsoleteFiles()
freeSpaceIfNeeded()
return if (!forceNewFile){
getReusableWritableFile() ?: createNewFile()
} else {
createNewFile()
}
}
There was a problem hiding this comment.
Yes, was not very sure which way to go here. Thanks for sharing your opinion, will change that :)
Codecov Report
@@ Coverage Diff @@
## feature/sdkv2 #1174 +/- ##
=================================================
+ Coverage 82.28% 82.29% +0.01%
=================================================
Files 353 354 +1
Lines 11796 11808 +12
Branches 2007 2014 +7
=================================================
+ Hits 9706 9717 +11
- Misses 1465 1469 +4
+ Partials 625 622 -3
|
d18426f to
83e6530
Compare
0xnm
left a comment
There was a problem hiding this comment.
Nice change! Finally we will get rid of the hack for the SR.
I've added some comments, mostly regarding the tests or typos.
|
|
||
| override fun withWriteContext(callback: (DatadogContext, EventBatchWriter) -> Unit) { | ||
| override fun withWriteContext( | ||
| forceNewBoolean: Boolean, |
There was a problem hiding this comment.
forceNewBatch, maybe? :)
| forceNewBoolean: Boolean, | |
| forceNewBatch: Boolean, |
There was a problem hiding this comment.
Damn...yes, miss typing
| internal interface FileOrchestrator { | ||
|
|
||
| /** | ||
| * @param forceNewBatch if `true` will force the orchestrator to start a new file. |
There was a problem hiding this comment.
Mismatch between name in the doc and name in the function signature. I suppose it should be forceNewFile here?
There was a problem hiding this comment.
yup....miss typing again
| interface FeatureScope { | ||
| /** | ||
| * Utility to write an event, asynchronously. | ||
| * @param forceNewBoolean if `true` forces the [EventBatchWriter] to write in a new file and |
There was a problem hiding this comment.
| * @param forceNewBoolean if `true` forces the [EventBatchWriter] to write in a new file and | |
| * @param forceNewBatch if `true` forces the [EventBatchWriter] to write in a new file and |
| */ | ||
| fun withWriteContext(callback: (DatadogContext, EventBatchWriter) -> Unit) | ||
| fun withWriteContext( | ||
| forceNewBoolean: Boolean = false, |
There was a problem hiding this comment.
| forceNewBoolean: Boolean = false, | |
| forceNewBatch: Boolean = false, |
| fun writeCurrentBatch(datadogContext: DatadogContext, callback: (EventBatchWriter) -> Unit) | ||
| fun writeCurrentBatch( | ||
| datadogContext: DatadogContext, | ||
| forceNewBatch: Boolean = false, |
There was a problem hiding this comment.
do we need to have the default value here if in all the calls (apart of the tests) we will get the value explicitly?
There was a problem hiding this comment.
Good question, need to check it out
| // region FeatureScope | ||
|
|
||
| @Test | ||
| @ParameterizedTest |
There was a problem hiding this comment.
not sure if we need a parametrized test here, given that we don't assert anything related to the forceNewBatch value.
We can simply use BoolForgery on the forceNewBatch test parameter. And coverage will be the same, because the only place where code path is different depending on the forceNewBatch parameter is BatchFileOrchestrator.
There was a problem hiding this comment.
Yeah but I rather make sure we test with both true/false value.
There was a problem hiding this comment.
IMO this would make sense if some assertion depends on that, which is not the case in most of the test. Anyway we already have kinda check of the proper flow by doing whenever(object.methodCall(parameter)), because if the parameter is not the one we provided in whenever, mock won't work and test will break anyway.
But I'm not pushing for it :)
|
|
||
| @Test | ||
| fun `𝕄 do nothing 𝕎 withWriteContext(callback) { no Datadog context }`() { | ||
| @ParameterizedTest |
There was a problem hiding this comment.
Same as above, BoolForgery is enough, no need for the parametrized test here and in other test files where ValueSource is just true or false.
| val end = System.currentTimeMillis() | ||
|
|
||
| // Then | ||
| checkNotNull(result) |
There was a problem hiding this comment.
I think it is better to use assertion method from AssertJ here instead of the Kotlin stdlib
| checkNotNull(result) | |
| assertThat(result).isNotNull() |
There was a problem hiding this comment.
hmm yes, I think I just duplicated that function so I need to change it also in the original.
There was a problem hiding this comment.
Yeah I think this is everywhere in this test class and removing it will imply other changes :(. I would rather keep it like this and maybe open a new PR.
|
|
||
| // When | ||
| val start = System.currentTimeMillis() | ||
| val result = testedOrchestrator.getWritableFile(forceNewFile = true) |
There was a problem hiding this comment.
I think result with forceNewFile = false will be the same, because it is the fresh state of the orchestrator and it will always return the new file.
What we need to do is to call getWritableFile twice (one is default call, another with forceNewFile = true) and check that second result is not the same as first and was created after the first call.
83e6530 to
351eae5
Compare
351eae5 to
7a0b30f
Compare
What does this PR do?
As a follow up task for the https://datadoghq.atlassian.net/wiki/spaces/RUMP/pages/2714764346/RFC+-+Handle+SR+data+storage+upload, we are adding a new option to the
FeatureScope#withWriterContextmethod to allow us to force the orchestrator to start a new batch before writing the new data.Motivation
What inspired you to submit this pull request?
Additional Notes
Anything else we should know when reviewing?
Review checklist (to be filled by reviewers)