add docker setup for generic replication IT
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..5b6fba0
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,8 @@
+test:
+ go test
+
+cover:
+ ./cover.sh
+
+dockertest:
+ ./dockertests/dockerTest.sh
diff --git a/dockertests/create-db.sql b/dockertests/create-db.sql
new file mode 100644
index 0000000..a1f46db
--- /dev/null
+++ b/dockertests/create-db.sql
@@ -0,0 +1,12 @@
+-- noinspection SqlDialectInspectionForFile
+-- noinspection SqlNoDataSourceInspectionForFile
+SET statement_timeout = 0;
+SET lock_timeout = 0;
+SET client_encoding = 'UTF8';
+SET standard_conforming_strings = on;
+SET check_function_bodies = false;
+SET client_min_messages = warning;
+SET row_security = off;
+
+CREATE DATABASE edgex WITH TEMPLATE = template0 ENCODING = 'UTF8';
+ALTER DATABASE edgex OWNER TO postgres;
diff --git a/dockertests/dockerCleanup.sh b/dockertests/dockerCleanup.sh
new file mode 100755
index 0000000..6a9437f
--- /dev/null
+++ b/dockertests/dockerCleanup.sh
@@ -0,0 +1,5 @@
+pgname=apidSync_test_pg
+ssname=apidSync_test_ss
+csname=apidSync_test_cs
+docker kill ${pgname} ${csname} ${ssname}
+docker rm -f ${pgname} ${csname} ${ssname}
\ No newline at end of file
diff --git a/dockertests/dockerTest.sh b/dockertests/dockerTest.sh
new file mode 100755
index 0000000..5c5a0cd
--- /dev/null
+++ b/dockertests/dockerTest.sh
@@ -0,0 +1,56 @@
+#!/usr/bin/env bash
+
+WORK_DIR=$(pwd)
+TRANSICATOR_DIR="$GOPATH/src/github.com/apigee-labs/transicator"
+DOCKER_IP="192.168.9.1"
+if [ "$(uname)" == Darwin ];
+then
+ DOCKER_IP="localhost"
+fi
+TEST_PG_BASE=postgres://postgres:changeme@$DOCKER_IP:5432
+TEST_PG_URL=postgres://postgres:changeme@$DOCKER_IP:5432/edgex
+echo ${TEST_PG_URL}
+
+export APIGEE_SYNC_DOCKER_IP=${DOCKER_IP}
+
+pgnum=$(docker images --filter "reference=apigeelabs/transicator-postgres" | wc -l)
+ssnum=$(docker images --filter "reference=apigeelabs/transicator-snapshot" | wc -l)
+csnum=$(docker images --filter "reference=apigeelabs/transicator-changeserver" | wc -l)
+
+
+if (( !(pgnum>1 && ssnum>1 && csnum>1) ))
+then
+ cd ${TRANSICATOR_DIR}
+ make
+ make docker
+ cd ${WORK_DIR}
+fi
+
+echo "Starting Transicator docker"
+pgname=apidSync_test_pg
+ssname=apidSync_test_ss
+csname=apidSync_test_cs
+
+# run PG
+docker run --name ${pgname} -p 5432:5432 -d -e POSTGRES_PASSWORD=changeme apigeelabs/transicator-postgres
+
+# Wait for PG to be up -- it takes a few seconds
+while `true`
+do
+ sleep 1
+ psql -q -c 'select * from now()' ${TEST_PG_BASE}
+ if [ $? -eq 0 ]
+ then
+ break
+ fi
+done
+
+# init pg
+psql -f ${WORK_DIR}/dockertests/create-db.sql ${TEST_PG_BASE}
+psql -f ${WORK_DIR}/dockertests/master-schema.sql ${TEST_PG_URL}
+psql -f ${WORK_DIR}/dockertests/user-setup.sql ${TEST_PG_URL}
+
+# run SS and CS
+docker run --name ${ssname} -d -p 9001:9001 apigeelabs/transicator-snapshot -p 9001 -u ${TEST_PG_URL}
+docker run --name ${csname} -d -p 9000:9000 apigeelabs/transicator-changeserver -p 9000 -u ${TEST_PG_URL} -s testslot
+
diff --git a/dockertests/docker_test.go b/dockertests/docker_test.go
new file mode 100644
index 0000000..72589e2
--- /dev/null
+++ b/dockertests/docker_test.go
@@ -0,0 +1,128 @@
+package dockertests
+
+import (
+ "github.com/30x/apidApigeeSync"
+ "github.com/30x/apid-core"
+ "github.com/apigee-labs/transicator/common"
+ . "github.com/onsi/ginkgo"
+ . "github.com/onsi/gomega"
+ "net/http"
+ "net/http/httptest"
+ "os"
+ "github.com/30x/apid-core/factory"
+ "github.com/Sirupsen/logrus"
+)
+
+const (
+ dockerCsPort string = "9000"
+ dockerSsPort string = "9001"
+ dockerPgPort string = "5432"
+ pluginName = "apigeeSyncDockerTest"
+ configLogLevel = "log_level"
+ configProxyServerBaseURI = "apigeesync_proxy_server_base"
+ configSnapServerBaseURI = "apigeesync_snapshot_server_base"
+ configChangeServerBaseURI = "apigeesync_change_server_base"
+ configConsumerKey = "apigeesync_consumer_key"
+ configConsumerSecret = "apigeesync_consumer_secret"
+ configApidClusterId = "apigeesync_cluster_id"
+ configSnapshotProtocol = "apigeesync_snapshot_proto"
+ configName = "apigeesync_instance_name"
+ ApigeeSyncEventSelector = "ApigeeSync"
+
+ // special value - set by ApigeeSync, not taken from configuration
+ configApidInstanceID = "apigeesync_apid_instance_id"
+ // This will not be needed once we have plugin handling tokens.
+ configBearerToken = "apigeesync_bearer_token"
+)
+
+
+var (
+ services apid.Services
+ log apid.LogService
+ data apid.DataService
+ config apid.ConfigService
+)
+/*
+ * This test suite acts like a dummy plugin. It listens to events emitted by
+ * apidApigeeSync and runs tests.
+ */
+
+var _ = Describe("dockerIT", func() {
+
+
+
+ BeforeSuite(func() {
+ hostname := os.Getenv("APIGEE_SYNC_DOCKER_IP")
+
+ apid.Initialize(factory.DefaultServicesFactory())
+ config = apid.Config()
+
+ // Set log level
+ config.Set(configLogLevel, logrus.DebugLevel.String())
+
+ // Auth Server
+ config.Set(configName, "dockerIT")
+ config.Set(configConsumerKey, "dummyKey")
+ config.Set(configConsumerSecret, "dummySecret")
+ config.Set(configApidClusterId, "testClusterId")
+ testServer := initDummyAuthServer()
+
+ // Setup dependencies
+ config.Set(configChangeServerBaseURI, hostname+":"+dockerCsPort)
+ config.Set(configSnapServerBaseURI, hostname+":"+dockerSsPort)
+ config.Set(configProxyServerBaseURI, testServer.URL)
+
+ // init plugin
+ apid.RegisterPlugin(initPlugin)
+ apid.InitializePlugins("dockerTest")
+ })
+
+
+
+ Context("Generic Replication", func() {
+ var _ = BeforeEach(func() {
+
+ })
+
+ It("should succesfully download table from pg", func() {
+ log.Debug("CS: " + config.GetString(configChangeServerBaseURI))
+ log.Debug("SS: " + config.GetString(configSnapServerBaseURI))
+ log.Debug("Auth: " + config.GetString(configProxyServerBaseURI))
+ })
+ })
+})
+
+func initDummyAuthServer() (testServer *httptest.Server) {
+ testRouter := apid.API().Router()
+ testServer = httptest.NewServer(testRouter)
+ // set up mock server
+ mockParms := apidApigeeSync.MockParms{
+ ReliableAPI: true,
+ ClusterID: config.GetString(configApidClusterId),
+ TokenKey: config.GetString(configConsumerKey),
+ TokenSecret: config.GetString(configConsumerSecret),
+ Scope: "dockerTest",
+ Organization: "dockerTest",
+ Environment: "prod",
+ }
+ apidApigeeSync.Mock(mockParms, testRouter)
+ return
+}
+
+func initPlugin(s apid.Services) (apid.PluginData, error) {
+ services = s
+ log = services.Log().ForModule(pluginName)
+ data = services.Data()
+
+ var pluginData = apid.PluginData {
+ Name: pluginName,
+ Version: "0.0.1",
+ ExtraData: map[string]interface{}{
+ "schemaVersion": "0.0.1",
+ },
+ }
+
+
+ log.Info(pluginName + " initialized.")
+ return pluginData, nil
+}
\ No newline at end of file
diff --git a/dockertests/master-schema.sql b/dockertests/master-schema.sql
new file mode 100644
index 0000000..b53c815
--- /dev/null
+++ b/dockertests/master-schema.sql
@@ -0,0 +1,116 @@
+CREATE SCHEMA IF NOT EXISTS edgex;
+ALTER DATABASE edgex SET search_path TO edgex;
+SET search_path TO edgex;
+
+CREATE TABLE apid_cluster (
+ id character varying(36) NOT NULL,
+ name text NOT NULL,
+ description text,
+ umbrella_org_app_name text NOT NULL,
+ created timestamp without time zone,
+ created_by text,
+ updated timestamp without time zone,
+ updated_by text,
+ _change_selector text,
+ CONSTRAINT apid_cluster_pkey PRIMARY KEY (id)
+);
+
+CREATE INDEX apid_cluster___change_selector_idx ON apid_cluster USING btree (_change_selector);
+CREATE INDEX apid_cluster_created_by_idx ON apid_cluster USING btree (created_by);
+
+CREATE TABLE data_scope (
+ id character varying(36) NOT NULL,
+ apid_cluster_id character varying(36) NOT NULL,
+ scope text NOT NULL,
+ org text,
+ env text,
+ created timestamp without time zone,
+ created_by text,
+ updated timestamp without time zone,
+ updated_by text,
+ _change_selector text,
+ CONSTRAINT data_scope_pkey PRIMARY KEY (id),
+ CONSTRAINT data_scope_apid_cluster_id_fk FOREIGN KEY (apid_cluster_id)
+ REFERENCES apid_cluster (id)
+ ON UPDATE NO ACTION ON DELETE CASCADE
+);
+CREATE INDEX apid_cluster_scope__change_selector_idx ON data_scope USING btree (_change_selector);
+CREATE INDEX apid_cluster_scope_apid_cluster_id_idx ON data_scope USING btree (apid_cluster_id);
+CREATE UNIQUE INDEX apid_cluster_scope_apid_cluster_id_org_env_idx ON data_scope USING btree (apid_cluster_id, org, env);
+CREATE INDEX data_scope_created_by_idx ON apid_cluster USING btree (created_by);
+
+
+CREATE TABLE bundle_config (
+ id character varying(36) NOT NULL,
+ data_scope_id character varying(36) NOT NULL,
+ name text NOT NULL,
+ uri text NOT NULL,
+ checksumType text,
+ checksum text,
+ created timestamp without time zone,
+ created_by text,
+ updated timestamp without time zone,
+ updated_by text,
+ CONSTRAINT bundle_config_pkey PRIMARY KEY (id),
+ CONSTRAINT bundle_config_data_scope_id_fk FOREIGN KEY (data_scope_id)
+ REFERENCES data_scope (id)
+ ON UPDATE NO ACTION ON DELETE CASCADE
+);
+
+CREATE INDEX bundle_config_data_scope_id_idx ON bundle_config USING btree (data_scope_id);
+CREATE INDEX bundle_config_created_by_idx ON apid_cluster USING btree (created_by);
+
+CREATE TABLE deployment (
+ id character varying(36) NOT NULL,
+ bundle_config_id character varying(36) NOT NULL,
+ apid_cluster_id character varying(36) NOT NULL,
+ data_scope_id character varying(36) NOT NULL,
+ bundle_config_name text NOT NULL,
+ bundle_config_json text NOT NULL,
+ config_json text NOT NULL,
+ created timestamp without time zone,
+ created_by text,
+ updated timestamp without time zone,
+ updated_by text,
+ _change_selector text,
+ CONSTRAINT deployment_pkey PRIMARY KEY (id),
+ CONSTRAINT deployment_bundle_config_id_fk FOREIGN KEY (bundle_config_id)
+ REFERENCES bundle_config (id)
+ ON UPDATE NO ACTION ON DELETE CASCADE
+);
+
+CREATE TABLE deployment_history (
+ id character varying(36) NOT NULL,
+ deployment_id character varying(36) NOT NULL,
+ action text NOT NULL,
+ bundle_config_id character varying(36),
+ apid_cluster_id character varying(36) NOT NULL,
+ data_scope_id character varying(36) NOT NULL,
+ bundle_config_json text NOT NULL,
+ config_json text NOT NULL,
+ created timestamp without time zone,
+ created_by text,
+ updated timestamp without time zone,
+ updated_by text,
+ CONSTRAINT deployment_history_pkey PRIMARY KEY (id)
+);
+
+CREATE INDEX deployment__change_selector_idx ON deployment USING btree (_change_selector);
+CREATE INDEX deployment_apid_cluster_id_idx ON deployment USING btree (apid_cluster_id);
+CREATE INDEX deployment_bundle_config_id_idx ON deployment USING btree (bundle_config_id);
+CREATE INDEX deployment_data_scope_id_idx ON deployment USING btree (data_scope_id);
+CREATE INDEX deployment_created_by_idx ON apid_cluster USING btree (created_by);
+
+CREATE TABLE configuration (
+ id character varying(36) NOT NULL,
+ body text NOT NULL DEFAULT '{}',
+ created timestamp without time zone,
+ created_by text,
+ updated timestamp without time zone,
+ updated_by text,
+ CONSTRAINT configuration_pkey PRIMARY KEY (id)
+);
+
+ALTER TABLE apid_cluster REPLICA IDENTITY FULL;
+ALTER TABLE data_scope REPLICA IDENTITY FULL;
+ALTER TABLE deployment REPLICA IDENTITY FULL;
\ No newline at end of file
diff --git a/dockertests/user-setup.sql b/dockertests/user-setup.sql
new file mode 100644
index 0000000..8068c40
--- /dev/null
+++ b/dockertests/user-setup.sql
@@ -0,0 +1 @@
+ALTER USER postgres SET search_path = edgex;
\ No newline at end of file