-
Notifications
You must be signed in to change notification settings - Fork 14
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
Apply java.nio.file.Files.createDirectories for Android SDK 26 or later to surface more error info #103
Open
TonyTangAndroid
wants to merge
28
commits into
uber:main
Choose a base branch
from
TonyTangAndroid:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Apply java.nio.file.Files.createDirectories for Android SDK 26 or later to surface more error info #103
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
f65f8d2
Update the minimum yml changes to make ci working
TonyTangAndroid 27ed6e7
Update the minimum gradle changes to support android api 30 Robolectr…
TonyTangAndroid e643582
Add rxjava2 as test dependencies
TonyTangAndroid 16bb64b
Add more SimpleStore and AtomicFile integration test
TonyTangAndroid dbad1e5
Fix the race condition issue on creating the parent folder.
TonyTangAndroid 3997ec0
Add AtomicFileConcurrentTest.kt
TonyTangAndroid 5cc34ad
Add AtomicFileConcurrentTest.kt that reproducing the failed exception
TonyTangAndroid 8685557
Bump up the ci
TonyTangAndroid 8c1bc76
Use `./gradlew spotlessApply` to fix the file format.
TonyTangAndroid 24f5f0f
Fix the release ci
TonyTangAndroid cfe78e0
Fix the main ci
TonyTangAndroid 09c9fb8
Fix the main ci
TonyTangAndroid 2ef8720
Fix the main ci by bumping down malinskiy/action-android
TonyTangAndroid 115d2ef
Fix the main ci by using RIBs
TonyTangAndroid 1733e14
Fix the main ci by using pure RIBs script
TonyTangAndroid fd3fa2f
Only apply to pull request
TonyTangAndroid 1419aa7
Make the ConcurrentTestUtil more intensive
TonyTangAndroid a677929
Ignore the flaky test
TonyTangAndroid 0438626
Refine the test comment
TonyTangAndroid e68a3a9
Keep original changes.
TonyTangAndroid faf1391
Apply the minimum fix with test code
TonyTangAndroid 9446f54
Apply java.nio.file.Files.createDirectories for Android SDK 26 or lat…
TonyTangAndroid bf929c9
Revert "Apply java.nio.file.Files.createDirectories for Android SDK 2…
TonyTangAndroid 790a1f2
Revert "Apply the minimum fix with test code"
TonyTangAndroid 5b77bd7
resolveParentFolder with Files.createDirectories without concurrent fix
TonyTangAndroid c2eae06
Revert "resolveParentFolder with Files.createDirectories without conc…
TonyTangAndroid f9100b1
resolveParentFolder with Files.createDirectories without concurrent fix
TonyTangAndroid 033d384
Add boilerplate test code
TonyTangAndroid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
simplestore/src/test/java/com/uber/simplestore/impl/AtomicFileConcurrentTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright (C) 2019. Uber Technologies | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.uber.simplestore.impl | ||
|
||
import android.app.Application | ||
import androidx.test.core.app.ApplicationProvider | ||
import com.google.common.truth.Truth.assertThat | ||
import com.uber.simplestore.impl.ConcurrentTestUtil.executeConcurrent | ||
import org.junit.Ignore | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.robolectric.RobolectricTestRunner | ||
import java.io.File | ||
import java.io.FileNotFoundException | ||
|
||
|
||
@RunWith(RobolectricTestRunner::class) | ||
class AtomicFileConcurrentTest { | ||
|
||
@Test(expected = FileNotFoundException::class) | ||
fun `case 0 when parent folder is absent will trigger FileNotFoundException`() { | ||
//arrange | ||
//makeParentFolder() | ||
val targetFile = createTargetFile() | ||
//act | ||
val target = targetFile.outputStream() | ||
//assert | ||
assertThat(target).isNotNull() | ||
} | ||
|
||
@Test | ||
fun `case 1 when parent folder is present will not trigger FileNotFoundException`() { | ||
//arrange | ||
makeParentFolder() | ||
val targetFile = createTargetFile() | ||
//act | ||
val target = targetFile.outputStream() | ||
//assert | ||
assertThat(target).isNotNull() | ||
} | ||
|
||
|
||
/** | ||
* This represents a typical file that stores a value for a random key. | ||
*/ | ||
private fun createTargetFile(): File { | ||
return File(app().dataDir, "files/simplestore/657b3cd7-f689-451b-aca0-628de60aa234/random_key") | ||
} | ||
|
||
/** | ||
* This presents a typical simple store folder scoped with under an `uuid`. | ||
*/ | ||
private fun makeParentFolder() { | ||
val parent = File(app().dataDir, "files/simplestore/657b3cd7-f689-451b-aca0-628de60aa234") | ||
parent.mkdirs() | ||
} | ||
|
||
private fun app(): Application { | ||
return ApplicationProvider.getApplicationContext() | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
simplestore/src/test/java/com/uber/simplestore/impl/ConcurrentTestUtil.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright (C) 2019. Uber Technologies | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.uber.simplestore.impl | ||
|
||
import net.jodah.concurrentunit.Waiter | ||
import java.util.concurrent.Executors | ||
|
||
|
||
/** | ||
* A utility class to execute a given action concurrently. | ||
* It will trigger [Waiter.fail] if the action throws an exception during the whole concurrent execution process. | ||
* It will trigger [Waiter.resume] if the action is concluded successfully for the whole concurrent execution. | ||
*/ | ||
object ConcurrentTestUtil { | ||
/** | ||
* The maximum number of threads to be executed concurrently. | ||
*/ | ||
private const val MAX_THREAD = 5 | ||
|
||
|
||
/** | ||
* Executes the given action concurrently. | ||
* It will trigger [Waiter.fail] if the action throws an exception during the whole concurrent execution process. | ||
* It will trigger [Waiter.resume] if the action is concluded successfully for the whole concurrent execution. | ||
*/ | ||
fun executeConcurrent(action: () -> Unit) { | ||
val waiter = Waiter() | ||
for (i in 0 until 1000) { | ||
val service = Executors.newFixedThreadPool(MAX_THREAD) | ||
for (j in 0 until 10) { | ||
service.submit { | ||
executeConcurrentInternally(action, waiter) | ||
} | ||
} | ||
} | ||
waiter.await(1000L * MAX_THREAD) | ||
} | ||
|
||
private fun executeConcurrentInternally(action: () -> Unit, waiter: Waiter) { | ||
try { | ||
run(action) | ||
} catch (e: Exception) { | ||
waiter.fail(e) | ||
} finally { | ||
waiter.resume() | ||
} | ||
} | ||
|
||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Those are minimum changes without introducing actual fix but to collect more information.