Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Briar Desktop
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
briar
Briar Desktop
Commits
d157ba0e
Commit
d157ba0e
authored
3 years ago
by
Sebastian
Browse files
Options
Downloads
Patches
Plain Diff
Rework DeterministicTestDataCreator to store contactIds mostly
parent
6608e994
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!54
When adding test data, hack GroupCount timestamp
Pipeline
#8736
passed
3 years ago
Changes
1
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/test/kotlin/org/briarproject/briar/desktop/testdata/DeterministicTestDataCreatorImpl.kt
+22
-23
22 additions, 23 deletions
...riar/desktop/testdata/DeterministicTestDataCreatorImpl.kt
with
22 additions
and
23 deletions
src/test/kotlin/org/briarproject/briar/desktop/testdata/DeterministicTestDataCreatorImpl.kt
+
22
−
23
View file @
d157ba0e
...
@@ -3,7 +3,6 @@ package org.briarproject.briar.desktop.testdata
...
@@ -3,7 +3,6 @@ package org.briarproject.briar.desktop.testdata
import
mu.KotlinLogging
import
mu.KotlinLogging
import
org.briarproject.bramble.api.FormatException
import
org.briarproject.bramble.api.FormatException
import
org.briarproject.bramble.api.client.ClientHelper
import
org.briarproject.bramble.api.client.ClientHelper
import
org.briarproject.bramble.api.contact.Contact
import
org.briarproject.bramble.api.contact.ContactId
import
org.briarproject.bramble.api.contact.ContactId
import
org.briarproject.bramble.api.contact.ContactManager
import
org.briarproject.bramble.api.contact.ContactManager
import
org.briarproject.bramble.api.crypto.SecretKey
import
org.briarproject.bramble.api.crypto.SecretKey
...
@@ -75,7 +74,7 @@ class DeterministicTestDataCreatorImpl @Inject internal constructor(
...
@@ -75,7 +74,7 @@ class DeterministicTestDataCreatorImpl @Inject internal constructor(
}
}
private
val
random
=
Random
()
private
val
random
=
Random
()
private
val
localAuthors
:
MutableMap
<
Contact
,
LocalAuthor
>
=
HashMap
()
private
val
localAuthors
:
MutableMap
<
Contact
Id
,
LocalAuthor
>
=
HashMap
()
override
fun
createTestData
(
override
fun
createTestData
(
numContacts
:
Int
,
numContacts
:
Int
,
numPrivateMsgs
:
Int
,
numPrivateMsgs
:
Int
,
...
@@ -120,8 +119,8 @@ class DeterministicTestDataCreatorImpl @Inject internal constructor(
...
@@ -120,8 +119,8 @@ class DeterministicTestDataCreatorImpl @Inject internal constructor(
}
}
@Throws
(
DbException
::
class
)
@Throws
(
DbException
::
class
)
private
fun
createContacts
(
numContacts
:
Int
,
avatarPercent
:
Int
):
List
<
Contact
>
{
private
fun
createContacts
(
numContacts
:
Int
,
avatarPercent
:
Int
):
List
<
Contact
Id
>
{
val
contacts
:
MutableList
<
Contact
>
=
ArrayList
(
numContacts
)
val
contacts
:
MutableList
<
Contact
Id
>
=
ArrayList
(
numContacts
)
val
localAuthor
=
identityManager
.
localAuthor
val
localAuthor
=
identityManager
.
localAuthor
for
(
i
in
0
until
min
(
numContacts
,
conversations
.
persons
.
size
))
{
for
(
i
in
0
until
min
(
numContacts
,
conversations
.
persons
.
size
))
{
...
@@ -142,7 +141,7 @@ class DeterministicTestDataCreatorImpl @Inject internal constructor(
...
@@ -142,7 +141,7 @@ class DeterministicTestDataCreatorImpl @Inject internal constructor(
alias
:
String
?,
alias
:
String
?,
avatarPercent
:
Int
,
avatarPercent
:
Int
,
date
:
LocalDateTime
,
date
:
LocalDateTime
,
):
Contact
{
):
Contact
Id
{
// prepare to add contact
// prepare to add contact
val
secretKey
=
secretKey
val
secretKey
=
secretKey
val
timestamp
=
clock
.
currentTimeMillis
()
val
timestamp
=
clock
.
currentTimeMillis
()
...
@@ -150,7 +149,7 @@ class DeterministicTestDataCreatorImpl @Inject internal constructor(
...
@@ -150,7 +149,7 @@ class DeterministicTestDataCreatorImpl @Inject internal constructor(
// prepare transport properties
// prepare transport properties
val
props
=
randomTransportProperties
val
props
=
randomTransportProperties
val
contact
=
db
.
transactionWithResult
<
Contact
,
RuntimeException
>(
false
)
{
txn
:
Transaction
->
val
contact
Id
=
db
.
transactionWithResult
<
Contact
Id
,
RuntimeException
>(
false
)
{
txn
:
Transaction
->
val
contactId
=
contactManager
.
addContact
(
val
contactId
=
contactManager
.
addContact
(
txn
,
remote
,
localAuthorId
,
secretKey
,
timestamp
,
true
,
verified
,
true
txn
,
remote
,
localAuthorId
,
secretKey
,
timestamp
,
true
,
verified
,
true
)
)
...
@@ -158,15 +157,14 @@ class DeterministicTestDataCreatorImpl @Inject internal constructor(
...
@@ -158,15 +157,14 @@ class DeterministicTestDataCreatorImpl @Inject internal constructor(
contactManager
.
setContactAlias
(
txn
,
contactId
,
alias
)
contactManager
.
setContactAlias
(
txn
,
contactId
,
alias
)
}
}
transportPropertyManager
.
addRemoteProperties
(
txn
,
contactId
,
props
)
transportPropertyManager
.
addRemoteProperties
(
txn
,
contactId
,
props
)
val
contact
=
db
.
getContact
(
txn
,
contactId
)
val
timestamp
=
date
.
toEpochSecond
(
ZoneOffset
.
UTC
)
*
1000
val
timestamp
=
date
.
toEpochSecond
(
ZoneOffset
.
UTC
)
*
1000
GroupCountHelper
.
resetGroupTimestamp
(
txn
,
contactId
,
messagingManager
,
clientHelper
,
timestamp
)
GroupCountHelper
.
resetGroupTimestamp
(
txn
,
contactId
,
messagingManager
,
clientHelper
,
timestamp
)
contact
contact
Id
}
}
if
(
random
.
nextInt
(
100
)
+
1
<=
avatarPercent
)
addAvatar
(
contact
)
if
(
random
.
nextInt
(
100
)
+
1
<=
avatarPercent
)
addAvatar
(
contact
Id
)
LOG
.
info
{
"Added contact ${remote.name} with transport properties: $props"
}
LOG
.
info
{
"Added contact ${remote.name} with transport properties: $props"
}
localAuthors
[
contact
]
=
remote
localAuthors
[
contact
Id
]
=
remote
return
contact
return
contact
Id
}
}
private
val
secretKey
:
SecretKey
private
val
secretKey
:
SecretKey
...
@@ -258,7 +256,8 @@ class DeterministicTestDataCreatorImpl @Inject internal constructor(
...
@@ -258,7 +256,8 @@ class DeterministicTestDataCreatorImpl @Inject internal constructor(
}
}
@Throws
(
DbException
::
class
)
@Throws
(
DbException
::
class
)
private
fun
addAvatar
(
c
:
Contact
)
{
private
fun
addAvatar
(
contactId
:
ContactId
)
{
val
c
=
contactManager
.
getContact
(
contactId
)
val
authorId
=
c
.
author
.
id
val
authorId
=
c
.
author
.
id
val
groupId
=
groupFactory
.
createGroup
(
val
groupId
=
groupFactory
.
createGroup
(
AvatarManager
.
CLIENT_ID
,
AvatarManager
.
CLIENT_ID
,
...
@@ -277,8 +276,8 @@ class DeterministicTestDataCreatorImpl @Inject internal constructor(
...
@@ -277,8 +276,8 @@ class DeterministicTestDataCreatorImpl @Inject internal constructor(
}
}
db
.
transaction
<
RuntimeException
>(
false
)
{
txn
:
Transaction
->
db
.
transaction
<
RuntimeException
>(
false
)
{
txn
:
Transaction
->
// TODO: Do this properly via clients without breaking encapsulation
// TODO: Do this properly via clients without breaking encapsulation
db
.
setGroupVisibility
(
txn
,
c
.
i
d
,
groupId
,
Group
.
Visibility
.
SHARED
)
db
.
setGroupVisibility
(
txn
,
c
ontactI
d
,
groupId
,
Group
.
Visibility
.
SHARED
)
db
.
receiveMessage
(
txn
,
c
.
i
d
,
m
)
db
.
receiveMessage
(
txn
,
c
ontactI
d
,
m
)
}
}
}
}
...
@@ -292,19 +291,19 @@ class DeterministicTestDataCreatorImpl @Inject internal constructor(
...
@@ -292,19 +291,19 @@ class DeterministicTestDataCreatorImpl @Inject internal constructor(
@Throws
(
DbException
::
class
)
@Throws
(
DbException
::
class
)
private
fun
createPrivateMessages
(
private
fun
createPrivateMessages
(
contacts
:
List
<
Contact
>,
contacts
:
List
<
Contact
Id
>,
numPrivateMsgs
:
Int
numPrivateMsgs
:
Int
)
{
)
{
for
(
i
in
contacts
.
indices
)
{
for
(
i
in
contacts
.
indices
)
{
val
contact
=
contacts
[
i
]
val
contact
Id
=
contacts
[
i
]
// this cannot cause an IndexOutOfBoundsException here with conversation.persons
// this cannot cause an IndexOutOfBoundsException here with conversation.persons
// because we already made sure to only create as many contacts as we have
// because we already made sure to only create as many contacts as we have
// conversation templates available.
// conversation templates available.
val
person
=
conversations
.
persons
[
i
]
val
person
=
conversations
.
persons
[
i
]
val
group
=
messagingManager
.
getCon
tactGroup
(
contact
)
val
group
Id
=
messagingManager
.
getCon
versationId
(
contact
Id
)
shareGroup
(
contact
.
i
d
,
group
.
i
d
)
shareGroup
(
contact
I
d
,
group
I
d
)
for
(
k
in
0
until
min
(
numPrivateMsgs
,
person
.
messages
.
size
))
{
for
(
k
in
0
until
min
(
numPrivateMsgs
,
person
.
messages
.
size
))
{
createPrivateMessage
(
contact
.
i
d
,
group
.
i
d
,
person
.
messages
[
k
])
createPrivateMessage
(
contact
I
d
,
group
I
d
,
person
.
messages
[
k
])
}
}
}
}
LOG
.
info
{
"Created $numPrivateMsgs private messages per contact."
}
LOG
.
info
{
"Created $numPrivateMsgs private messages per contact."
}
...
@@ -351,7 +350,7 @@ class DeterministicTestDataCreatorImpl @Inject internal constructor(
...
@@ -351,7 +350,7 @@ class DeterministicTestDataCreatorImpl @Inject internal constructor(
}
}
@Throws
(
DbException
::
class
)
@Throws
(
DbException
::
class
)
private
fun
createPrivateGroups
(
contacts
:
List
<
Contact
>,
numPrivateGroups
:
Int
):
List
<
PrivateGroup
>
{
private
fun
createPrivateGroups
(
contacts
:
List
<
Contact
Id
>,
numPrivateGroups
:
Int
):
List
<
PrivateGroup
>
{
val
privateGroups
:
MutableList
<
PrivateGroup
>
=
ArrayList
(
numPrivateGroups
)
val
privateGroups
:
MutableList
<
PrivateGroup
>
=
ArrayList
(
numPrivateGroups
)
for
(
i
in
0
until
min
(
numPrivateGroups
,
GROUP_NAMES
.
size
))
{
for
(
i
in
0
until
min
(
numPrivateGroups
,
GROUP_NAMES
.
size
))
{
// create private group
// create private group
...
@@ -365,8 +364,8 @@ class DeterministicTestDataCreatorImpl @Inject internal constructor(
...
@@ -365,8 +364,8 @@ class DeterministicTestDataCreatorImpl @Inject internal constructor(
privateGroupManager
.
addPrivateGroup
(
privateGroup
,
joinMsg
,
true
)
privateGroupManager
.
addPrivateGroup
(
privateGroup
,
joinMsg
,
true
)
// share with all contacts
// share with all contacts
for
(
contact
in
contacts
)
{
for
(
contact
Id
in
contacts
)
{
shareGroup
(
contact
.
i
d
,
privateGroup
.
id
)
shareGroup
(
contact
I
d
,
privateGroup
.
id
)
}
}
privateGroups
.
add
(
privateGroup
)
privateGroups
.
add
(
privateGroup
)
}
}
...
@@ -377,7 +376,7 @@ class DeterministicTestDataCreatorImpl @Inject internal constructor(
...
@@ -377,7 +376,7 @@ class DeterministicTestDataCreatorImpl @Inject internal constructor(
@Throws
(
DbException
::
class
)
@Throws
(
DbException
::
class
)
private
fun
createRandomPrivateGroupMessages
(
private
fun
createRandomPrivateGroupMessages
(
privateGroup
:
PrivateGroup
,
privateGroup
:
PrivateGroup
,
contacts
:
List
<
Contact
>,
contacts
:
List
<
Contact
Id
>,
numPrivateGroupMessages
:
Int
numPrivateGroupMessages
:
Int
)
{
)
{
// TODO
// TODO
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment