Fix cassandra statestore error - "Bind variables cannot be used for table names" - Introduce `fmt.Sprintf` where applicable (#1388)
* - Introduce `fmt.Sprintf` where applicable - Add conformance test for cassandra component. Signed-off-by: mbimbij <joseph.mbimbi@gmail.com> * Start cassandra via docker-compose for its conformance test Signed-off-by: mbimbij <joseph.mbimbi@gmail.com> * Apply `go fmt` on `tests/conformance/common.go` as part of PR correction Signed-off-by: mbimbij <joseph.mbimbi@gmail.com>
This commit is contained in:
parent
0f97b52b90
commit
1389ae5937
|
|
@ -0,0 +1,15 @@
|
|||
version: '2'
|
||||
|
||||
services:
|
||||
cassandra:
|
||||
image: docker.io/bitnami/cassandra:4.0.1
|
||||
ports:
|
||||
- '7000:7000'
|
||||
- '9042:9042'
|
||||
volumes:
|
||||
- 'cassandra_data:/bitnami'
|
||||
environment:
|
||||
- CASSANDRA_PASSWORD=cassandra
|
||||
volumes:
|
||||
cassandra_data:
|
||||
driver: local
|
||||
|
|
@ -69,6 +69,7 @@ jobs:
|
|||
- state.sqlserver
|
||||
- state.postgresql
|
||||
- state.mysql
|
||||
- state.cassandra
|
||||
EOF
|
||||
)
|
||||
echo "::set-output name=pr-components::$PR_COMPONENTS"
|
||||
|
|
@ -284,6 +285,10 @@ jobs:
|
|||
docker-compose -f ./.github/infrastructure/docker-compose-postgresql.yml -p postgresql up -d
|
||||
if: contains(matrix.component, 'postgresql')
|
||||
|
||||
- name: Start cassandra
|
||||
run: |
|
||||
docker-compose -f ./.github/infrastructure/docker-compose-cassandra.yml -p cassandra up -d
|
||||
if: contains(matrix.component, 'cassandra')
|
||||
|
||||
- name: Setup KinD test data
|
||||
if: contains(matrix.component, 'kubernetes')
|
||||
|
|
|
|||
|
|
@ -223,7 +223,7 @@ func getCassandraMetadata(metadata state.Metadata) (*cassandraMetadata, error) {
|
|||
|
||||
// Delete performs a delete operation.
|
||||
func (c *Cassandra) Delete(req *state.DeleteRequest) error {
|
||||
return c.session.Query("DELETE FROM ? WHERE key = ?", c.table, req.Key).Exec()
|
||||
return c.session.Query(fmt.Sprintf("DELETE FROM %s WHERE key = ?", c.table), req.Key).Exec()
|
||||
}
|
||||
|
||||
// Get retrieves state from cassandra with a key.
|
||||
|
|
@ -246,7 +246,7 @@ func (c *Cassandra) Get(req *state.GetRequest) (*state.GetResponse, error) {
|
|||
session = sess
|
||||
}
|
||||
|
||||
results, err := session.Query("SELECT value FROM ? WHERE key = ?", c.table, req.Key).Iter().SliceMap()
|
||||
results, err := session.Query(fmt.Sprintf("SELECT value FROM %s WHERE key = ?", c.table), req.Key).Iter().SliceMap()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -294,10 +294,10 @@ func (c *Cassandra) Set(req *state.SetRequest) error {
|
|||
}
|
||||
|
||||
if ttl != nil {
|
||||
return session.Query("INSERT INTO ? (key, value) VALUES (?, ?) USING TTL ?", c.table, req.Key, bt, *ttl).Exec()
|
||||
return session.Query(fmt.Sprintf("INSERT INTO %s (key, value) VALUES (?, ?) USING TTL ?", c.table), req.Key, bt, *ttl).Exec()
|
||||
}
|
||||
|
||||
return session.Query("INSERT INTO ? (key, value) VALUES (?, ?)", c.table, req.Key, bt).Exec()
|
||||
return session.Query(fmt.Sprintf("INSERT INTO %s (key, value) VALUES (?, ?)", c.table), req.Key, bt).Exec()
|
||||
}
|
||||
|
||||
func (c *Cassandra) Ping() error {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
apiVersion: dapr.io/v1alpha1
|
||||
kind: Component
|
||||
metadata:
|
||||
name: statestore
|
||||
spec:
|
||||
type: state.cassandra
|
||||
version: v1
|
||||
metadata:
|
||||
- name: hosts
|
||||
value: localhost
|
||||
- name: username
|
||||
value: cassandra
|
||||
- name: password
|
||||
value: cassandra
|
||||
|
||||
|
|
@ -23,3 +23,6 @@ components:
|
|||
- component: azure.tablestorage
|
||||
allOperations: false
|
||||
operations: ["set", "get", "delete", "etag", "bulkset", "bulkdelete", "first-write"]
|
||||
- component: cassandra
|
||||
allOperations: false
|
||||
operations: [ "set", "get", "delete", "bulkset", "bulkdelete" ]
|
||||
|
|
@ -55,6 +55,7 @@ import (
|
|||
ss_local_file "github.com/dapr/components-contrib/secretstores/local/file"
|
||||
s_cosmosdb "github.com/dapr/components-contrib/state/azure/cosmosdb"
|
||||
s_azuretablestorage "github.com/dapr/components-contrib/state/azure/tablestorage"
|
||||
s_cassandra "github.com/dapr/components-contrib/state/cassandra"
|
||||
s_mongodb "github.com/dapr/components-contrib/state/mongodb"
|
||||
s_mysql "github.com/dapr/components-contrib/state/mysql"
|
||||
s_postgresql "github.com/dapr/components-contrib/state/postgresql"
|
||||
|
|
@ -409,6 +410,8 @@ func loadStateStore(tc TestComponent) state.Store {
|
|||
store = s_mysql.NewMySQLStateStore(testLogger)
|
||||
case "azure.tablestorage":
|
||||
store = s_azuretablestorage.NewAzureTablesStateStore(testLogger)
|
||||
case "cassandra":
|
||||
store = s_cassandra.NewCassandraStateStore(testLogger)
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue