Last active
September 21, 2017 23:13
-
-
Save koral--/373ba87d1c558b3faf50afb46a302159 to your computer and use it in GitHub Desktop.
Too many open files
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
package pl.droidsonroids.edgetest | |
import android.content.res.AssetFileDescriptor | |
import android.support.test.InstrumentationRegistry | |
import org.junit.Assert | |
import org.junit.Test | |
class TooManyOpenFilesTest { | |
//asset named "test" required | |
@Test | |
fun tooManyOpenFilesDemo() { | |
val context = InstrumentationRegistry.getContext() | |
val assets = context.assets | |
val descriptors = mutableListOf<AssetFileDescriptor>() | |
try { | |
for (i in 0..1024) { | |
descriptors.add(assets.openFd("test")) | |
} | |
} catch (e: Exception) { | |
e.printStackTrace() //java.io.FileNotFoundException: This file can not be opened as a file descriptor; it is probably compressed | |
} | |
try { | |
context.openFileOutput("test", 0) | |
} catch (e: Exception) { | |
e.printStackTrace() //java.io.FileNotFoundException: /data/user/0/pl.droidsonroids.edgetest/files/test (Too many open files) | |
} | |
val sharedPreferences = context.getSharedPreferences("test", 0) | |
Assert.assertTrue(sharedPreferences.edit().putBoolean("test", true).commit()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment