Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KSmigielski committed Aug 31, 2023
1 parent a5ff490 commit 46935f6
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ import pl.allegro.tech.servicemesh.envoycontrol.snapshot.resource.routes.EnvoyEg
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.resource.routes.EnvoyIngressRoutesFactory
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.resource.routes.ServiceTagMetadataGenerator
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.serviceDependencies
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.CLUSTER_NAME
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.CURRENT_ZONE
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.DEFAULT_CLUSTER_WEIGHTS
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.DEFAULT_DISCOVERY_SERVICE_NAME
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.DEFAULT_IDLE_TIMEOUT
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.DEFAULT_SERVICE_NAME
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.EGRESS_HOST
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.EGRESS_PORT
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.INGRESS_HOST
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.INGRESS_PORT
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.TRAFFIC_SPLITTING_FORCE_TRAFFIC_ZONE
import pl.allegro.tech.servicemesh.envoycontrol.utils.CLUSTER_NAME
import pl.allegro.tech.servicemesh.envoycontrol.utils.CURRENT_ZONE
import pl.allegro.tech.servicemesh.envoycontrol.utils.DEFAULT_CLUSTER_WEIGHTS
import pl.allegro.tech.servicemesh.envoycontrol.utils.DEFAULT_DISCOVERY_SERVICE_NAME
import pl.allegro.tech.servicemesh.envoycontrol.utils.DEFAULT_IDLE_TIMEOUT
import pl.allegro.tech.servicemesh.envoycontrol.utils.DEFAULT_SERVICE_NAME
import pl.allegro.tech.servicemesh.envoycontrol.utils.EGRESS_HOST
import pl.allegro.tech.servicemesh.envoycontrol.utils.EGRESS_PORT
import pl.allegro.tech.servicemesh.envoycontrol.utils.INGRESS_HOST
import pl.allegro.tech.servicemesh.envoycontrol.utils.INGRESS_PORT
import pl.allegro.tech.servicemesh.envoycontrol.utils.TRAFFIC_SPLITTING_FORCE_TRAFFIC_ZONE
import pl.allegro.tech.servicemesh.envoycontrol.utils.createCluster
import pl.allegro.tech.servicemesh.envoycontrol.utils.createClusterConfigurations
import pl.allegro.tech.servicemesh.envoycontrol.utils.createEndpoints
Expand All @@ -56,7 +56,6 @@ class EnvoySnapshotFactoryTest {
const val SERVICE_NAME_2 = "service-name-2"
}

private val defaultClusterWeights = mapOf("main" to 50, "secondary" to 50)
private val snapshotPropertiesWithWeights = SnapshotProperties().also {
it.loadBalancing.trafficSplitting.serviceByWeightsProperties = mapOf(
DEFAULT_SERVICE_NAME to DEFAULT_CLUSTER_WEIGHTS
Expand Down Expand Up @@ -270,7 +269,7 @@ class EnvoySnapshotFactoryTest {
val defaultProperties = SnapshotProperties().also {
it.dynamicListeners.enabled = false
it.loadBalancing.trafficSplitting.serviceByWeightsProperties = mapOf(
DEFAULT_SERVICE_NAME to defaultClusterWeights
DEFAULT_SERVICE_NAME to DEFAULT_CLUSTER_WEIGHTS
)
it.loadBalancing.trafficSplitting.zoneName = "not-matching-dc"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import org.junit.jupiter.api.Test
import pl.allegro.tech.servicemesh.envoycontrol.groups.DependencySettings
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.GlobalSnapshot
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.SnapshotProperties
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.AGGREGATE_CLUSTER_NAME
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.CLUSTER_NAME1
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.CLUSTER_NAME2
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.DEFAULT_SERVICE_NAME
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.MAIN_CLUSTER_NAME
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.SECONDARY_CLUSTER_NAME
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.TRAFFIC_SPLITTING_FORCE_TRAFFIC_ZONE
import pl.allegro.tech.servicemesh.envoycontrol.utils.AGGREGATE_CLUSTER_NAME
import pl.allegro.tech.servicemesh.envoycontrol.utils.CLUSTER_NAME1
import pl.allegro.tech.servicemesh.envoycontrol.utils.CLUSTER_NAME2
import pl.allegro.tech.servicemesh.envoycontrol.utils.DEFAULT_CLUSTER_WEIGHTS
import pl.allegro.tech.servicemesh.envoycontrol.utils.DEFAULT_SERVICE_NAME
import pl.allegro.tech.servicemesh.envoycontrol.utils.MAIN_CLUSTER_NAME
import pl.allegro.tech.servicemesh.envoycontrol.utils.SECONDARY_CLUSTER_NAME
import pl.allegro.tech.servicemesh.envoycontrol.utils.TRAFFIC_SPLITTING_FORCE_TRAFFIC_ZONE
import pl.allegro.tech.servicemesh.envoycontrol.utils.createAllServicesGroup
import pl.allegro.tech.servicemesh.envoycontrol.utils.createCluster
import pl.allegro.tech.servicemesh.envoycontrol.utils.createClusterConfigurations
Expand All @@ -29,7 +29,7 @@ internal class EnvoyClustersFactoryTest {
private val factory = EnvoyClustersFactory(SnapshotProperties())
private val snapshotPropertiesWithWeights = SnapshotProperties().apply {
loadBalancing.trafficSplitting.serviceByWeightsProperties = mapOf(
DEFAULT_SERVICE_NAME to TestData.DEFAULT_CLUSTER_WEIGHTS
DEFAULT_SERVICE_NAME to DEFAULT_CLUSTER_WEIGHTS
)
loadBalancing.trafficSplitting.zoneName = TRAFFIC_SPLITTING_FORCE_TRAFFIC_ZONE
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import pl.allegro.tech.servicemesh.envoycontrol.snapshot.LoadBalancingProperties
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.RouteSpecification
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.SnapshotProperties
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.TrafficSplittingProperties
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.WeightRouteSpecification
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.ZoneWeights
import pl.allegro.tech.servicemesh.envoycontrol.utils.zoneWeights
import java.util.concurrent.ConcurrentHashMap
import java.util.stream.Stream

Expand Down Expand Up @@ -58,7 +61,7 @@ internal class EnvoyEndpointsFactoryTest {

private val serviceName2 = "service-two"

private val defaultWeights = mapOf("main" to 50, "secondary" to 50)
private val defaultWeights = zoneWeights(50, 50)

private val defaultZone = "DC1"

Expand Down Expand Up @@ -537,7 +540,7 @@ internal class EnvoyEndpointsFactoryTest {
}

private fun snapshotPropertiesWithTrafficSplitting(
serviceByWeights: Map<String, Map<String, Int>>,
serviceByWeights: Map<String, ZoneWeights>,
zone: String = defaultZone
) =
SnapshotProperties().apply {
Expand All @@ -547,8 +550,8 @@ internal class EnvoyEndpointsFactoryTest {
}
}

private fun String.toRouteSpecification(weights: Map<String, Int> = defaultWeights): RouteSpecification {
return RouteSpecification(this, listOf(), DependencySettings(), weights)
private fun String.toRouteSpecification(weights: ZoneWeights = defaultWeights): RouteSpecification {
return WeightRouteSpecification(this, listOf(), DependencySettings(), weights)
}

private fun String.toClusterLoadAssignment(): ClusterLoadAssignment = ClusterLoadAssignment.newBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ import pl.allegro.tech.servicemesh.envoycontrol.groups.matchingOnMethod
import pl.allegro.tech.servicemesh.envoycontrol.groups.matchingOnPrefix
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.RouteSpecification
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.SnapshotProperties
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.StandardRouteSpecification

internal class EnvoyEgressRoutesFactoryTest {

val clusters = listOf(
RouteSpecification(
StandardRouteSpecification(
clusterName = "srv1",
routeDomains = listOf("srv1"),
settings = DependencySettings(
Expand Down Expand Up @@ -171,8 +172,8 @@ internal class EnvoyEgressRoutesFactoryTest {
egress.headersToRemove = mutableListOf("x-special-case-header", "x-custom")
})
val routesSpecifications = listOf(
RouteSpecification("example_pl_1553", listOf("example.pl:1553"), DependencySettings()),
RouteSpecification("example_com_1553", listOf("example.com:1553"), DependencySettings())
StandardRouteSpecification("example_pl_1553", listOf("example.pl:1553"), DependencySettings()),
StandardRouteSpecification("example_com_1553", listOf("example.com:1553"), DependencySettings())
)

// when
Expand Down Expand Up @@ -203,7 +204,7 @@ internal class EnvoyEgressRoutesFactoryTest {
val routesFactory = EnvoyEgressRoutesFactory(SnapshotProperties())
val retryPolicy = RetryPolicy(methods = setOf("GET", "POST"))
val routesSpecifications = listOf(
RouteSpecification("example", listOf("example.pl:1553"), DependencySettings(retryPolicy = retryPolicy)),
StandardRouteSpecification("example", listOf("example.pl:1553"), DependencySettings(retryPolicy = retryPolicy)),
)

val routeConfig = routesFactory.createEgressRouteConfig(
Expand Down Expand Up @@ -234,7 +235,7 @@ internal class EnvoyEgressRoutesFactoryTest {
val routesFactory = EnvoyEgressRoutesFactory(SnapshotProperties())
val retryPolicy = RetryPolicy(numberRetries = 3)
val routesSpecifications = listOf(
RouteSpecification("example", listOf("example.pl:1553"), DependencySettings(retryPolicy = retryPolicy)),
StandardRouteSpecification("example", listOf("example.pl:1553"), DependencySettings(retryPolicy = retryPolicy)),
)

val routeConfig = routesFactory.createEgressRouteConfig(
Expand All @@ -259,7 +260,7 @@ internal class EnvoyEgressRoutesFactoryTest {
// given
val routesFactory = EnvoyEgressRoutesFactory(SnapshotProperties())
val routesSpecifications = listOf(
RouteSpecification("example", listOf("example.pl:1553"), DependencySettings()),
StandardRouteSpecification("example", listOf("example.pl:1553"), DependencySettings()),
)

val routeConfig = routesFactory.createEgressRouteConfig(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ import io.envoyproxy.envoy.config.core.v3.ConfigSource
import io.envoyproxy.envoy.config.core.v3.HttpProtocolOptions
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.ClusterConfiguration
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.SnapshotProperties
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.CLUSTER_NAME

fun createCluster(
defaultProperties: SnapshotProperties = SnapshotProperties(),
clusterName: String = CLUSTER_NAME,
idleTimeout: Long = TestData.DEFAULT_IDLE_TIMEOUT
idleTimeout: Long = DEFAULT_IDLE_TIMEOUT
): Cluster {
return Cluster.newBuilder().setName(clusterName)
.setType(Cluster.DiscoveryType.EDS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import io.envoyproxy.envoy.config.cluster.v3.Cluster
import io.envoyproxy.envoy.config.endpoint.v3.ClusterLoadAssignment
import io.envoyproxy.envoy.config.endpoint.v3.LbEndpoint
import io.envoyproxy.envoy.config.endpoint.v3.LocalityLbEndpoints
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.CURRENT_ZONE

fun createLoadAssignments(clusters: List<Cluster>): List<ClusterLoadAssignment> {
return clusters.map {
Expand All @@ -18,7 +17,7 @@ fun createLoadAssignments(clusters: List<Cluster>): List<ClusterLoadAssignment>
fun createEndpoints(): List<LocalityLbEndpoints> =
listOf(
createEndpoint(CURRENT_ZONE),
createEndpoint(TestData.TRAFFIC_SPLITTING_FORCE_TRAFFIC_ZONE)
createEndpoint(TRAFFIC_SPLITTING_FORCE_TRAFFIC_ZONE)
)

fun createEndpoint(zone: String): LocalityLbEndpoints {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
package pl.allegro.tech.servicemesh.envoycontrol.utils

import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.DEFAULT_DISCOVERY_SERVICE_NAME
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.DEFAULT_SERVICE_NAME
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.EGRESS_HOST
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.EGRESS_PORT
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.INGRESS_HOST
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.INGRESS_PORT
import pl.allegro.tech.servicemesh.envoycontrol.groups.AccessLogFilterSettings
import pl.allegro.tech.servicemesh.envoycontrol.groups.AllServicesGroup
import pl.allegro.tech.servicemesh.envoycontrol.groups.CommunicationMode
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
package pl.allegro.tech.servicemesh.envoycontrol.utils

object TestData {
const val INGRESS_HOST = "ingress-host"
const val INGRESS_PORT = 3380
const val EGRESS_HOST = "egress-host"
const val EGRESS_PORT = 3380
const val DEFAULT_IDLE_TIMEOUT = 100L
const val DEFAULT_SERVICE_NAME = "service-name"
const val DEFAULT_DISCOVERY_SERVICE_NAME = "discovery-service-name"
const val CLUSTER_NAME = "cluster-name"
const val CLUSTER_NAME1 = "cluster-1"
const val CLUSTER_NAME2 = "cluster-2"
const val MAIN_CLUSTER_NAME = "cluster-1"
const val SECONDARY_CLUSTER_NAME = "cluster-1-secondary"
const val AGGREGATE_CLUSTER_NAME = "cluster-1-aggregate"
const val TRAFFIC_SPLITTING_FORCE_TRAFFIC_ZONE = "dc2"
const val CURRENT_ZONE = "dc1"
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.ZoneWeights

val DEFAULT_CLUSTER_WEIGHTS = mapOf("main" to 50, "secondary" to 50)

const val INGRESS_HOST = "ingress-host"
const val INGRESS_PORT = 3380
const val EGRESS_HOST = "egress-host"
const val EGRESS_PORT = 3380
const val DEFAULT_IDLE_TIMEOUT = 100L
const val DEFAULT_SERVICE_NAME = "service-name"
const val DEFAULT_DISCOVERY_SERVICE_NAME = "discovery-service-name"
const val CLUSTER_NAME = "cluster-name"
const val CLUSTER_NAME1 = "cluster-1"
const val CLUSTER_NAME2 = "cluster-2"
const val MAIN_CLUSTER_NAME = "cluster-1"
const val SECONDARY_CLUSTER_NAME = "cluster-1-secondary"
const val AGGREGATE_CLUSTER_NAME = "cluster-1-aggregate"
const val TRAFFIC_SPLITTING_FORCE_TRAFFIC_ZONE = "dc2"
const val CURRENT_ZONE = "dc1"

val DEFAULT_CLUSTER_WEIGHTS = zoneWeights(50, 50)

fun zoneWeights(main: Int, secondary: Int) = ZoneWeights().also {
it.main = main
it.secondary = secondary
}

0 comments on commit 46935f6

Please sign in to comment.