Skip to content

Commit

Permalink
Introduce a locally runnable matching simulator
Browse files Browse the repository at this point in the history
  • Loading branch information
taylanisikdemir committed Jul 31, 2024
1 parent f9996a1 commit 698c0ec
Show file tree
Hide file tree
Showing 33 changed files with 1,412 additions and 64 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ test_eventsV2
test_eventsV2.log
test_eventsV2_xdc
test_eventsV2_xdc.log
matching-simulator-output/

# Executables produced by cadence repo
/cadence
Expand Down
77 changes: 77 additions & 0 deletions common/archiver/provider/noop_provider.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Copyright (c) 2017 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package provider

import (
"context"

"github.com/uber/cadence/common/archiver"
)

type noOpArchiverProvider struct{}

func NewNoOpArchiverProvider() ArchiverProvider {
return &noOpArchiverProvider{}
}

func (*noOpArchiverProvider) RegisterBootstrapContainer(
serviceName string,
historyContainer *archiver.HistoryBootstrapContainer,
visibilityContainter *archiver.VisibilityBootstrapContainer,
) error {
return nil
}

func (*noOpArchiverProvider) GetHistoryArchiver(scheme, serviceName string) (archiver.HistoryArchiver, error) {
return &noOpHistoryArchiver{}, nil
}

func (*noOpArchiverProvider) GetVisibilityArchiver(scheme, serviceName string) (archiver.VisibilityArchiver, error) {
return &noOpVisibilityArchiver{}, nil
}

type noOpHistoryArchiver struct{}

func (*noOpHistoryArchiver) Archive(context.Context, archiver.URI, *archiver.ArchiveHistoryRequest, ...archiver.ArchiveOption) error {
return nil
}

func (*noOpHistoryArchiver) Get(context.Context, archiver.URI, *archiver.GetHistoryRequest) (*archiver.GetHistoryResponse, error) {
return &archiver.GetHistoryResponse{}, nil
}

func (*noOpHistoryArchiver) ValidateURI(archiver.URI) error {
return nil
}

type noOpVisibilityArchiver struct{}

func (*noOpVisibilityArchiver) Archive(context.Context, archiver.URI, *archiver.ArchiveVisibilityRequest, ...archiver.ArchiveOption) error {
return nil
}

func (*noOpVisibilityArchiver) Query(context.Context, archiver.URI, *archiver.QueryVisibilityRequest) (*archiver.QueryVisibilityResponse, error) {
return &archiver.QueryVisibilityResponse{}, nil
}

func (*noOpVisibilityArchiver) ValidateURI(archiver.URI) error {
return nil
}
3 changes: 3 additions & 0 deletions common/resource/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/uber-go/tally"
"go.uber.org/cadence/.gen/go/cadence/workflowserviceclient"

"github.com/uber/cadence/client/history"
"github.com/uber/cadence/common"
"github.com/uber/cadence/common/archiver"
"github.com/uber/cadence/common/archiver/provider"
Expand Down Expand Up @@ -80,5 +81,7 @@ type (
PinotClient pinot.GenericClient
AsyncWorkflowQueueProvider queue.Provider
TimeSource clock.TimeSource
// HistoryClientFn is used by integration tests to mock a history client
HistoryClientFn func() history.Client
}
)
9 changes: 8 additions & 1 deletion common/resource/resourceImpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,14 @@ func New(
serviceConfig.IsErrorRetryableFunction,
)

historyRawClient := clientBean.GetHistoryClient()
var historyRawClient history.Client
if params.HistoryClientFn != nil {
logger.Debug("Using history client from HistoryClientFn")
historyRawClient = params.HistoryClientFn()
} else {
logger.Debug("Using history client from bean")
historyRawClient = clientBean.GetHistoryClient()

Check warning on line 248 in common/resource/resourceImpl.go

View check run for this annotation

Codecov / codecov/patch

common/resource/resourceImpl.go#L242-L248

Added lines #L242 - L248 were not covered by tests
}
historyClient := retryable.NewHistoryClient(
historyRawClient,
common.CreateHistoryServiceRetryPolicy(),
Expand Down
56 changes: 56 additions & 0 deletions docker/buildkite/docker-compose-local-matching-simulation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
version: "3.5"

services:
cassandra:
image: cassandra:4.1.1
environment:
- "MAX_HEAP_SIZE=256M"
- "HEAP_NEWSIZE=128M"
expose:
- "9042"
networks:
services-network:
aliases:
- cassandra
healthcheck:
test: ["CMD", "cqlsh", "-u cassandra", "-p cassandra" ,"-e describe keyspaces"]
interval: 15s
timeout: 30s
retries: 10

matching-simulator:
build:
context: ../../
dockerfile: ./docker/buildkite/Dockerfile
command:
- /bin/sh
- -e
- -c
- >
go test -timeout 180s
-run ^TestMatchingSimulationSuite$
-count 1
-v
github.com/uber/cadence/host
| tee test.log
environment:
- "MATCHING_LOG_EVENTS=true"
- "CASSANDRA_HOST=cassandra"
- "CASSANDRA=1"
- "CASSANDRA_SEEDS=cassandra"
depends_on:
cassandra:
condition: service_healthy
volumes:
- ../../:/cadence
- /cadence/.build/ # ensure we don't mount the build directory
- /cadence/.bin/ # ensure we don't mount the bin directory
networks:
services-network:
aliases:
- integration-test

networks:
services-network:
name: services-network
driver: bridge
5 changes: 5 additions & 0 deletions host/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/uber/cadence/client/admin"
"github.com/uber/cadence/client/frontend"
"github.com/uber/cadence/client/history"
"github.com/uber/cadence/client/matching"
"github.com/uber/cadence/client/wrappers/thrift"
"github.com/uber/cadence/common/service"
)
Expand All @@ -48,6 +49,10 @@ type HistoryClient interface {
history.Client
}

type MatchingClient interface {
matching.Client
}

// NewAdminClient creates a client to cadence admin client
func NewAdminClient(d *yarpc.Dispatcher) AdminClient {
return thrift.NewAdminClient(adminserviceclient.New(d.ClientConfig(testOutboundName(service.Frontend))))
Expand Down
6 changes: 2 additions & 4 deletions host/integrationbase.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ package host
import (
"context"
"fmt"
"io/ioutil"
"os"
"testing"
"time"
Expand Down Expand Up @@ -148,7 +147,6 @@ func (s *IntegrationBase) setupLogger() {

// GetTestClusterConfig return test cluster config
func GetTestClusterConfig(configFile string) (*TestClusterConfig, error) {

if err := environment.SetupEnv(); err != nil {
return nil, err
}
Expand All @@ -159,7 +157,7 @@ func GetTestClusterConfig(configFile string) (*TestClusterConfig, error) {
}
// This is just reading a config so it's less of a security concern
// #nosec
confContent, err := ioutil.ReadFile(configLocation)
confContent, err := os.ReadFile(configLocation)
if err != nil {
return nil, fmt.Errorf("failed to read test cluster config file %v: %v", configLocation, err)
}
Expand Down Expand Up @@ -190,7 +188,7 @@ func GetTestClusterConfigs(configFile string) ([]*TestClusterConfig, error) {
fileName = TestFlags.TestClusterConfigFile
}

confContent, err := ioutil.ReadFile(fileName)
confContent, err := os.ReadFile(fileName)
if err != nil {
return nil, fmt.Errorf("failed to read test cluster config file %v: %v", fileName, err)
}
Expand Down
Loading

0 comments on commit 698c0ec

Please # to comment.