blob: 4ef31480505816101356545d84834cfab743c629 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
/***************************************************************************************************
* Copyright © All Contributors. See LICENSE and AUTHORS in the root directory for details.
**************************************************************************************************/
package at.bitfire.ical4android
import android.Manifest
import android.accounts.Account
import android.content.ContentProviderClient
import android.content.ContentUris
import android.net.Uri
import android.provider.CalendarContract
import androidx.test.filters.FlakyTest
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.rule.GrantPermissionRule
import at.bitfire.ical4android.impl.TestCalendar
import at.bitfire.ical4android.impl.TestEvent
import at.bitfire.ical4android.util.MiscUtils.ContentProviderClientHelper.closeCompat
import net.fortuna.ical4j.model.property.Attendee
import net.fortuna.ical4j.model.property.DtEnd
import net.fortuna.ical4j.model.property.DtStart
import org.junit.*
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotNull
import java.net.URI
import java.util.*
class BatchOperationTest {
companion object {
@JvmField
@ClassRule
val permissionRule = GrantPermissionRule.grant(
Manifest.permission.READ_CALENDAR,
Manifest.permission.WRITE_CALENDAR
)
lateinit var provider: ContentProviderClient
@BeforeClass
@JvmStatic
fun connectProvider() {
provider = InstrumentationRegistry.getInstrumentation().targetContext.contentResolver.acquireContentProviderClient(CalendarContract.AUTHORITY)!!
}
@AfterClass
@JvmStatic
fun closeProvider() {
provider.closeCompat()
}
}
private val testAccount = Account("ical4android@example.com", CalendarContract.ACCOUNT_TYPE_LOCAL)
private lateinit var calendarUri: Uri
private lateinit var calendar: TestCalendar
@Before
fun prepare() {
System.gc()
calendar = TestCalendar.findOrCreate(testAccount, provider)
assertNotNull(calendar)
calendarUri = ContentUris.withAppendedId(CalendarContract.Calendars.CONTENT_URI, calendar.id)
}
@After
fun shutdown() {
calendar.delete()
System.gc()
}
@Test
fun testTransactionSplitting() {
val event = Event()
event.uid = "sample1@testLargeTransaction"
event.summary = "Large event"
event.dtStart = DtStart("20150502T120000Z")
event.dtEnd = DtEnd("20150502T130000Z")
for (i in 0 until 2000) // 2000 attendees are enough for a transaction split to happen
event.attendees += Attendee(URI("mailto:att$i@example.com"))
val uri = TestEvent(calendar, event).add()
val testEvent = calendar.findById(ContentUris.parseId(uri))
try {
assertEquals(2000, testEvent.event!!.attendees.size)
} finally {
testEvent.delete()
}
}
@FlakyTest
@Test
fun testLargeTransactionSplitting() {
// with 4000 attendees, this test has been observed to fail on the CI server docker emulator.
// Too many Binders are sent to SYSTEM (see issue #42). Asking for GC in @Before/@After might help.
val event = Event()
event.uid = "sample1@testLargeTransaction"
event.summary = "Large event"
event.dtStart = DtStart("20150502T120000Z")
event.dtEnd = DtEnd("20150502T130000Z")
for (i in 0 until 4000)
event.attendees += Attendee(URI("mailto:att$i@example.com"))
val uri = TestEvent(calendar, event).add()
val testEvent = calendar.findById(ContentUris.parseId(uri))
try {
assertEquals(4000, testEvent.event!!.attendees.size)
} finally {
testEvent.delete()
}
}
@Test(expected = CalendarStorageException::class)
fun testLargeTransactionSingleRow() {
val event = Event()
event.uid = "sample1@testLargeTransaction"
event.dtStart = DtStart("20150502T120000Z")
event.dtEnd = DtEnd("20150502T130000Z")
// 1 MB SUMMARY ... have fun
val data = CharArray(1024*1024)
Arrays.fill(data, 'x')
event.summary = String(data)
TestEvent(calendar, event).add()
}
}
|