Skip to content

Commit

Permalink
Merge branch 'develop' into feature/seagull-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
la3lma authored Dec 3, 2019
2 parents 3548c39 + 0fbc4db commit 80826a3
Show file tree
Hide file tree
Showing 26 changed files with 1,535 additions and 1,661 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

[![Kotlin version badge](https://img.shields.io/badge/kotlin-1.3.60-blue.svg)](http://kotlinlang.org/)
[![Kotlin version badge](https://img.shields.io/badge/kotlin-1.3.61-blue.svg)](http://kotlinlang.org/)
[![Prime version](https://img.shields.io/github/tag/ostelco/ostelco-core.svg)](https://github.com/ostelco/ostelco-core/tags)
[![GitHub license](https://img.shields.io/github/license/ostelco/ostelco-core.svg)](https://github.com/ostelco/ostelco-core/blob/master/LICENSE)

Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ plugins {
id("project-report")
id("com.github.ben-manes.versions") version "0.27.0"
jacoco
kotlin("jvm") version "1.3.60" apply false
kotlin("jvm") version "1.3.61" apply false
id("com.google.protobuf") version "0.8.10" apply false
id("com.github.johnrengelman.shadow") version "5.2.0" apply false
idea
Expand Down
20 changes: 10 additions & 10 deletions buildSrc/src/main/kotlin/org/ostelco/prime/gradle/Version.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package org.ostelco.prime.gradle
object Version {
const val assertJ = "3.14.0"

const val arrow = "0.8.2"
const val arrow = "0.10.3"

const val byteBuddy = "1.10.3"
const val byteBuddy = "1.10.4"
const val csv = "1.7"
const val cxf = "3.3.4"
const val dockerComposeJunitRule = "1.3.0"
const val dropwizard = "1.3.16"
const val dropwizard = "1.3.17"
const val metrics = "4.1.1"
const val firebase = "6.11.0"

Expand All @@ -33,23 +33,23 @@ object Version {
const val jdbi3 = "3.11.1"
const val jjwt = "0.10.7"
const val junit5 = "5.5.2"
const val kotlin = "1.3.60"
const val kotlinXCoroutines = "1.3.2"
const val mockito = "3.1.0"
const val kotlin = "1.3.61"
const val kotlinXCoroutines = "1.3.2-1.3.60"
const val mockito = "3.2.0"
const val mockitoKotlin = "2.2.0"
const val neo4jDriver = "1.7.5"
const val neo4j = "3.5.12"
const val neo4j = "3.5.13"
const val opencensus = "0.24.0"
const val postgresql = "42.2.8" // See comment in ./sim-administration/simmanager/build.gradle
const val prometheusDropwizard = "2.2.0"
const val protoc = "3.10.0"
const val protoc = "3.11.0"
const val slf4j = "1.7.29"
// IMPORTANT: When Stripe SDK library version is updated, check if the Stripe API version has changed.
// If so, then update API version in Stripe Web Console for callback Webhooks.
const val stripe = "15.4.0"
const val stripe = "15.7.0"
const val swagger = "2.1.0"
const val swaggerCodegen = "2.4.10"
const val testcontainers = "1.12.3"
const val testcontainers = "1.12.4"
const val tink = "1.2.2"
const val zxing = "3.4.0"
}
2,381 changes: 1,145 additions & 1,236 deletions neo4j-store/src/main/kotlin/org/ostelco/prime/storage/graph/Neo4jStore.kt

Large diffs are not rendered by default.

42 changes: 19 additions & 23 deletions neo4j-store/src/main/resources/OnNewCustomerAction.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import arrow.core.Either
import arrow.core.fix
import arrow.effects.IO
import arrow.instances.either.monad.monad
import arrow.core.extensions.fx
import org.ostelco.prime.dsl.WriteTransaction
import org.ostelco.prime.dsl.withSku
import org.ostelco.prime.model.Customer
Expand All @@ -23,25 +21,23 @@ object : OnNewCustomerAction {

val welcomePackProductSku = "2GB_FREE_ON_JOINING"

return IO {
Either.monad<StoreError>().binding {
WriteTransaction(transaction).apply {
val product = get(Product withSku welcomePackProductSku).bind()
createPurchaseRecord(
customer.id,
PurchaseRecord(
id = UUID.randomUUID().toString(),
product = product,
timestamp = Instant.now().toEpochMilli()
)
).bind()
applyProduct(
customerId = customer.id,
product = product
).bind()
}
Unit
}.fix()
}.unsafeRunSync()
return Either.fx {
WriteTransaction(transaction).apply {
val (product) = get(Product withSku welcomePackProductSku)
createPurchaseRecord(
customer.id,
PurchaseRecord(
id = UUID.randomUUID().toString(),
product = product,
timestamp = Instant.now().toEpochMilli()
)
).bind()
applyProduct(
customerId = customer.id,
product = product
).bind()
}
Unit
}
}
}
32 changes: 14 additions & 18 deletions neo4j-store/src/main/resources/OnRegionApprovedAction.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import arrow.core.Either
import arrow.core.fix
import arrow.core.getOrElse
import arrow.effects.IO
import arrow.instances.either.monad.monad
import arrow.core.extensions.fx
import org.ostelco.prime.auditlog.AuditLog
import org.ostelco.prime.dsl.WriteTransaction
import org.ostelco.prime.dsl.withId
Expand All @@ -19,19 +16,18 @@ object : OnRegionApprovedAction {
regionCode: String,
transaction: PrimeTransaction
): Either<StoreError, Unit> {
return IO {
Either.monad<StoreError>().binding {
WriteTransaction(transaction).apply {
val segmentId = get(Segment withId "plan-country-${regionCode.toLowerCase()}")
.getOrElse {
get(Segment withId "country-${regionCode.toLowerCase()}").bind()
}
.id
fact { (Customer withId customer.id) belongsToSegment (Segment withId segmentId) }.bind()
AuditLog.info(customer.id, "Added customer to segment - $segmentId")
}
Unit
}.fix()
}.unsafeRunSync()
return Either.fx {
WriteTransaction(transaction).apply {
val segmentId = get(Segment withId "plan-country-${regionCode.toLowerCase()}")
.fold(
{ get(Segment withId "country-${regionCode.toLowerCase()}").bind() },
{ it }
)
.id
fact { (Customer withId customer.id) belongsToSegment (Segment withId segmentId) }.bind()
AuditLog.info(customer.id, "Added customer to segment - $segmentId")
}
Unit
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ import org.ostelco.prime.model.Customer
import org.ostelco.prime.model.Identity
import org.ostelco.prime.model.Price
import org.ostelco.prime.model.Product
import org.ostelco.prime.model.ProductClass.SIMPLE_DATA
import org.ostelco.prime.model.ProductProperties.NO_OF_BYTES
import org.ostelco.prime.model.ProductProperties.PRODUCT_CLASS
import org.ostelco.prime.model.Region
import org.ostelco.prime.storage.graph.model.Segment
import java.util.*
import java.util.concurrent.CountDownLatch
import kotlin.system.measureTimeMillis
import kotlin.test.BeforeTest
import kotlin.test.Ignore
Expand All @@ -45,15 +47,26 @@ class Neo4jLoadTest {
create {
Product(sku = "2GB_FREE_ON_JOINING",
price = Price(0, ""),
properties = mapOf(NO_OF_BYTES.s to "2_147_483_648"))
properties = mapOf(
PRODUCT_CLASS.s to SIMPLE_DATA.name,
NO_OF_BYTES.s to "${2.GiB()}"
)
)
}
create {
Product(sku = "1GB_FREE_ON_REFERRED",
price = Price(0, ""),
properties = mapOf(NO_OF_BYTES.s to "1_000_000_000"))
properties = mapOf(
PRODUCT_CLASS.s to SIMPLE_DATA.name,
NO_OF_BYTES.s to "1_000_000_000"
)
)
}
create {
Segment(id = "country-$COUNTRY_CODE}")
}
create {
Segment(id = "country-${COUNTRY.toLowerCase()}")
Region(id = COUNTRY_CODE, name = "Norway")
}
}
}
Expand Down Expand Up @@ -87,18 +100,14 @@ class Neo4jLoadTest {

val durationInMillis = measureTimeMillis {

val cdl = CountDownLatch(COUNT)

runBlocking(Dispatchers.Default) {
repeat(COUNT) { i ->
launch {
Neo4jStoreSingleton.consume(msisdn = "${i % USERS}", usedBytes = USED, requestedBytes = REQUESTED) { storeResult ->
storeResult.fold(
storeResult.bimap(
{ fail(it.message) },
{
// println("Balance = %,d, Granted = %,d".format(it.second, it.first))
cdl.countDown()
assert(true)
// println("Balance = %,d, Granted = %,d".format(it.balance, it.granted))
})
}
}
Expand All @@ -107,8 +116,6 @@ class Neo4jLoadTest {
// Wait for all the responses to be returned
println("Waiting for all responses to be returned")
}

cdl.await()
}

// Print load test results
Expand All @@ -120,7 +127,7 @@ class Neo4jLoadTest {
.fold(
{ fail(it.message) },
{
assertEquals(expected = 100_000_000 - COUNT / USERS * USED - REQUESTED,
assertEquals(expected = 2.GiB() - COUNT / USERS * USED - REQUESTED,
actual = it.single().balance,
message = "Balance does not match")
}
Expand All @@ -136,7 +143,7 @@ class Neo4jLoadTest {
const val REQUESTED = 100L

const val NAME = "Test User"
const val COUNTRY = "NO"
const val COUNTRY_CODE = "no"

@ClassRule
@JvmField
Expand Down Expand Up @@ -196,4 +203,6 @@ class Neo4jLoadTest {
Neo4jClient.stop()
}
}
}
}

fun Int.GiB() = this.toLong() * 1024 * 1024 * 1024
Loading

0 comments on commit 80826a3

Please sign in to comment.