Skip to content

Commit

Permalink
Added test code
Browse files Browse the repository at this point in the history
  • Loading branch information
stefink committed Jun 28, 2022
1 parent d2b2296 commit b74cb70
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 0 deletions.
18 changes: 18 additions & 0 deletions test/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
all: run-kafka-server run-grpc-server

run-kafka-server:
docker-compose -f ./resources/docker-compose.yaml up -d
docker exec broker kafka-topics --bootstrap-server broker:9092 --create --topic dblogs

run-grpc-server:
go run server/grpc_server.go

send-log-to-endpoint:
curl --header "Content-Type: application/json" --request POST --data '{"DataDomainID":"5", "Database":"accuknox","Operation":"select", "OperationDetails":"none", "Timestamp":"2022-06-17T09:35:38Z","User":"ada_demo_user"}' http://127.0.0.1:8080/log

demo:
go run main.go

clean:
docker-compose -f ./resources/docker-compose.yaml down

27 changes: 27 additions & 0 deletions test/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
version: '3'
services:
zookeeper:
image: confluentinc/cp-zookeeper:7.0.1
container_name: zookeeper
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000

broker:
image: confluentinc/cp-kafka:7.0.1
container_name: broker
ports:
# To learn about configuring Kafka for access across networks see
# https://www.confluent.io/blog/kafka-client-cannot-connect-to-broker-on-aws-on-docker-etc/
- "9092:9092"
depends_on:
- zookeeper
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: 'zookeeper:2181'
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_INTERNAL:PLAINTEXT
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:9092,PLAINTEXT_INTERNAL://broker:29092
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1
KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
9 changes: 9 additions & 0 deletions test/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package main

import (
"github.com/datasage-io/datasage/src/integrations"
)

func main() {
integrations.RunServer()
}
37 changes: 37 additions & 0 deletions test/server/grpc_server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package main

import (
"context"
"fmt"
"log"
"net"

config "github.com/datasage-io/datasage/src/integrations/grpc_config"
"google.golang.org/grpc"
)

type server struct {
config.UnimplementedDataSageServerServer
}

func (s *server) LogSend(ctx context.Context, in *config.Log) (*config.Null, error) {
log.Printf("GRPC: Receive message body from client: %s", in.Body)
return &config.Null{}, nil
}

func RunGRPCServer() {
listen, err := net.Listen("tcp", ":2222")
if err != nil {
log.Fatalf("failed to listen: %v", err)
}
grpcServer := grpc.NewServer()
fmt.Println("gRPC Server listening on :2222")
config.RegisterDataSageServerServer(grpcServer, &server{})
if err := grpcServer.Serve(listen); err != nil {
log.Fatalf("failed to serve: %s", err)
}
}

func main() {
RunGRPCServer()
}
40 changes: 40 additions & 0 deletions test/src/conf/datasage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
application:
name: Datasage

logging:
level: INFO

server:
port: 1989
database: sqlite

database:
external:
name: datasage
host: localhost
user: datasage
pass: datasage
port: 1234

adaptors:
name: mysql
version: 5.7
env: k8s
is_operator: yes
percona: yes
host: 122.122.122.1
username: root
password: abcdef

integrations:
kafka:
- topic: dblogs
broker: 127.0.0.1
port: 9092
rpc:
- host: 127.0.0.1
port: 2222
http:
- endpoint: https://accuknox.com/service/log
method: post

0 comments on commit b74cb70

Please sign in to comment.