-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RUMM-2767 Add the 'forceNewBatch' option into the FeatureScope #1174
RUMM-2767 Add the 'forceNewBatch' option into the FeatureScope #1174
Conversation
de732cb
to
404b92a
Compare
404b92a
to
06b450a
Compare
@@ -56,6 +56,17 @@ internal class BatchFileOrchestrator( | |||
return reusableFile ?: createNewFile() | |||
} | |||
|
|||
override fun getNewWritableFile(): File? { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice change! Finally we will get rid of the hack for the SR.
I've added some comments, mostly regarding the tests or typos.
@@ -126,17 +126,18 @@ internal class SdkFeature( | |||
|
|||
// region FeatureScope | |||
|
|||
override fun withWriteContext(callback: (DatadogContext, EventBatchWriter) -> Unit) { | |||
override fun withWriteContext( | |||
forceNewBoolean: Boolean, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
forceNewBatch
, maybe? :)
forceNewBoolean: Boolean, | |
forceNewBatch: Boolean, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Damn...yes, miss typing
@@ -21,11 +21,13 @@ import java.io.File | |||
internal interface FileOrchestrator { | |||
|
|||
/** | |||
* @param forceNewBatch if `true` will force the orchestrator to start a new file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup....miss typing again
@@ -14,10 +14,15 @@ import com.datadog.android.v2.api.context.DatadogContext | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @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 |
* @param callback an operation called with an up-to-date [DatadogContext] | ||
* and an [EventBatchWriter]. Callback will be executed on a worker thread from I/O pool | ||
*/ | ||
fun withWriteContext(callback: (DatadogContext, EventBatchWriter) -> Unit) | ||
fun withWriteContext( | ||
forceNewBoolean: Boolean = false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question, need to check it out
@@ -266,8 +268,10 @@ internal class SdkFeatureTest { | |||
|
|||
// region FeatureScope | |||
|
|||
@Test | |||
@ParameterizedTest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah but I rather make sure we test with both true/false value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 :)
@@ -291,16 +301,19 @@ internal class SdkFeatureTest { | |||
) | |||
} | |||
|
|||
@Test | |||
fun `𝕄 do nothing 𝕎 withWriteContext(callback) { no Datadog context }`() { | |||
@ParameterizedTest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
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#withWriterContext
method 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)