Skip to content

Commit

Permalink
Sarthak: Added parallel execution support for table. added Awaitality…
Browse files Browse the repository at this point in the history
… to test parallel execution,
  • Loading branch information
msarthak32 committed Nov 9, 2017
1 parent 2b9874f commit d916978
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 4 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@
<version>42.1.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
5 changes: 3 additions & 2 deletions src/main/kotlin/com/github/dataanon/dsl/Strategy.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import com.github.dataanon.model.DbConfig
import com.github.dataanon.model.Table
import com.github.dataanon.utils.ProgressBarGenerator
import reactor.core.publisher.Flux
import reactor.core.scheduler.Schedulers

abstract class Strategy {
protected val tables = mutableListOf<Table>()

fun execute(limit: Long = -1, progressBarEnabled: Boolean = true) {
Flux.fromIterable(tables)
// .parallel()
// .runOn(Schedulers.parallel())
.parallel()
.runOn(Schedulers.parallel())
.log()
.subscribe { table -> executeOnTable(table, limit, progressBarEnabled) }
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/com/github/dataanon/model/Table.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.github.dataanon.utils.DefaultAnonymizationStrategies

abstract class Table(val name: String) {
private val columnStrategyContainer = mutableMapOf<String, ColumnStrategy>()
var whereCondition = ""
internal var whereCondition = ""

fun anonymize(columnName: String): ColumnStrategy {
val columnStrategy = ColumnStrategy()
Expand All @@ -28,7 +28,7 @@ abstract class Table(val name: String) {
}

internal fun generateSelectQuery(limit: Long): String {
val columns = allColumns().joinToString(",")
val columns = allColumns().joinToString(",")
val limitClause = if(limit > 0) " LIMIT $limit " else ""
val whereClause = if(whereCondition.isNotEmpty()) " WHERE $whereCondition " else ""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import com.github.dataanon.model.DbConfig
import com.github.dataanon.strategy.string.FixedString
import com.github.dataanon.support.MoviesTable
import io.kotlintest.specs.FunSpec
import org.awaitility.Awaitility.await
import java.sql.Date
import java.util.concurrent.TimeUnit
import java.util.regex.Pattern
import kotlin.test.assertEquals
import kotlin.test.assertTrue
Expand All @@ -31,6 +33,7 @@ class SpecialFeaturesIntegrationTest : FunSpec() {
anonymize("GENRE").using(FixedString("Action"))
}.execute(progressBarEnabled = false)

await().timeout(2, TimeUnit.SECONDS).until { destTable.findAll()[0]["TITLE"].toString().equals("MY VALUE") }
val records = destTable.findAll()

assertEquals(1, records.size)
Expand All @@ -54,6 +57,7 @@ class SpecialFeaturesIntegrationTest : FunSpec() {
anonymize("GENRE")
}.execute(progressBarEnabled = true)

await().timeout(2, TimeUnit.SECONDS).until { moviesTable.findAll()[0]["TITLE"].toString().equals("MY VALUE") }
val records = moviesTable.findAll()

assertEquals(1, records.size)
Expand Down Expand Up @@ -81,6 +85,7 @@ class SpecialFeaturesIntegrationTest : FunSpec() {
anonymize("GENRE").using(FixedString("Action"))
}.execute(limit = 1, progressBarEnabled = false)

await().timeout(2, TimeUnit.SECONDS).until { destTable.findAll()[0]["TITLE"].toString().equals("MY VALUE") }
val records = destTable.findAll()

assertEquals(1, records.size)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import com.github.dataanon.model.DbConfig
import com.github.dataanon.strategy.string.FixedString
import com.github.dataanon.support.MoviesTable
import io.kotlintest.specs.FunSpec
import org.awaitility.Awaitility.await
import java.sql.Date
import java.util.concurrent.TimeUnit
import java.util.regex.Pattern
import kotlin.test.assertEquals
import kotlin.test.assertTrue
Expand All @@ -25,6 +27,7 @@ class BlacklistMoviesSimplePrimaryKeyIntegrationTest : FunSpec() {
anonymize("GENRE")
}.execute(progressBarEnabled = false)

await().timeout(2, TimeUnit.SECONDS).until { moviesTable.findAll()[0]["TITLE"].toString().equals("MY VALUE") }
val records = moviesTable.findAll()

assertEquals(1,records.size)
Expand All @@ -46,6 +49,7 @@ class BlacklistMoviesSimplePrimaryKeyIntegrationTest : FunSpec() {
anonymize("GENRE")
}.execute(progressBarEnabled = false)

await().timeout(2, TimeUnit.SECONDS).until { moviesTable.findAll()[0]["TITLE"].toString().equals("MY VALUE") }
val records = moviesTable.findAll()

assertEquals(2,records.size)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import com.github.dataanon.strategy.string.FixedString
import com.github.dataanon.support.MoviesTable
import com.github.dataanon.support.RatingsTable
import io.kotlintest.specs.FunSpec
import org.awaitility.Awaitility.await
import java.sql.Date
import java.sql.Timestamp
import java.util.concurrent.TimeUnit
import java.util.regex.Pattern
import kotlin.test.assertEquals
import kotlin.test.assertTrue
Expand All @@ -31,6 +33,7 @@ class BlacklistMultipleTableIntegrationTest : FunSpec() {
}
.execute(progressBarEnabled = false)

await().timeout(2, TimeUnit.SECONDS).until { moviesTable.findAll()[0]["TITLE"].toString().equals("MY VALUE") }
val moviesRecords = moviesTable.findAll()
val ratingRecords = ratingsTable.findAll()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import com.github.dataanon.model.DbConfig
import com.github.dataanon.strategy.number.FixedInt
import com.github.dataanon.support.RatingsTable
import io.kotlintest.specs.FunSpec
import org.awaitility.Awaitility.await
import java.sql.Timestamp
import java.util.concurrent.TimeUnit
import kotlin.test.assertEquals

class BlacklistRatingsCompositePrimaryKeyIntegrationTest : FunSpec() {
Expand All @@ -19,6 +21,7 @@ class BlacklistRatingsCompositePrimaryKeyIntegrationTest : FunSpec() {
anonymize("RATING").using(FixedInt(3))
}.execute(progressBarEnabled = false)

await().timeout(2, TimeUnit.SECONDS).until { ratingsTable.findAll()[0]["RATING"].toString().equals("3") }
val records = ratingsTable.findAll()

assertEquals(2,records.size)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import com.github.dataanon.model.DbConfig
import com.github.dataanon.strategy.string.FixedString
import com.github.dataanon.support.MoviesTable
import io.kotlintest.specs.FunSpec
import org.awaitility.Awaitility.await
import java.sql.Date
import java.util.concurrent.TimeUnit
import java.util.regex.Pattern
import kotlin.test.assertEquals
import kotlin.test.assertTrue
Expand All @@ -29,6 +31,7 @@ class WhitelistMoviesSimplePrimaryKeyIntegrationTest : FunSpec() {
anonymize("RELEASE_DATE")
}.execute(progressBarEnabled = false)

await().timeout(2, TimeUnit.SECONDS).until { destTable.findAll()[0]["TITLE"].toString().equals("MY VALUE") }
val records = destTable.findAll()

assertEquals(2,records.size)
Expand Down

0 comments on commit d916978

Please sign in to comment.