@@ -34,7 +34,7 @@ func (a *DualWriteAndCommonTableTestcase) RunTests(ctx context.Context, t *testi
3434 a .testBasicRequest (ctx , t )
3535 a .testIngestToClickHouseWorks (ctx , t )
3636 //a.testIngestToCommonTableWorks(ctx, t)
37- // a.testDualQueryReturnsDataFromClickHouse(ctx, t)
37+ a .testDualQueryReturnsDataFromClickHouse (ctx , t )
3838 a .testDualWritesWork (ctx , t )
3939 a .testWildcardGoesToElastic (ctx , t )
4040 return nil
@@ -49,6 +49,71 @@ func (a *DualWriteAndCommonTableTestcase) testBasicRequest(ctx context.Context,
4949 assert .Equal (t , http .StatusOK , resp .StatusCode )
5050}
5151
52+ func (a * DualWriteAndCommonTableTestcase ) testDualQueryReturnsDataFromClickHouse (ctx context.Context , t * testing.T ) {
53+ resp , err := a .RequestToQuesma (ctx , "POST" , "/logs-dual-query/_doc" , []byte (`{"name": "Przemyslaw", "age": 31337}` ))
54+ if err != nil {
55+ t .Fatalf ("Failed to insert document: %s" , err )
56+ }
57+ defer resp .Body .Close ()
58+ assert .Equal (t , http .StatusOK , resp .StatusCode )
59+
60+ chQuery := "SELECT * FROM 'logs-dual-query'"
61+ rows , err := a .ExecuteClickHouseQuery (ctx , chQuery )
62+ if err != nil {
63+ t .Fatalf ("Failed to execute query: %s" , err )
64+ }
65+ columnTypes , err := rows .ColumnTypes ()
66+ values := make ([]interface {}, len (columnTypes ))
67+ valuePtrs := make ([]interface {}, len (columnTypes ))
68+ for i := range values {
69+ valuePtrs [i ] = & values [i ]
70+ }
71+ var name string
72+ var age int
73+ for rows .Next () {
74+ if err := rows .Scan (valuePtrs ... ); err != nil {
75+ t .Fatalf ("Failed to scan row: %s" , err )
76+ }
77+ for i , col := range values {
78+ switch columnTypes [i ].Name () {
79+ case "name" :
80+ if v , ok := col .(* string ); ok {
81+ name = * v
82+ }
83+ case "age" :
84+ if v , ok := col .(* int64 ); ok {
85+ age = int (* v )
86+ }
87+ }
88+ }
89+ if name == "Przemyslaw" && age == 31337 {
90+ break
91+ }
92+ }
93+ assert .Equal (t , "Przemyslaw" , name )
94+ assert .Equal (t , 31337 , age )
95+
96+ // In the meantime let's delete the index from Elasticsearch
97+ _ , _ = a .RequestToElasticsearch (ctx , "DELETE" , "/logs-dual-query" , nil )
98+ if err != nil {
99+ t .Fatalf ("Failed to make DELETE request: %s" , err )
100+ }
101+ // FINAL TEST - WHETHER QUESMA RETURNS DATA FROM CLICKHOUSE
102+ resp , err = a .RequestToQuesma (ctx , "GET" , "/logs-dual-query/_search" , []byte (`{"query": {"match_all": {}}}` ))
103+ if err != nil {
104+ t .Fatalf ("Failed to make GET request: %s" , err )
105+ }
106+ defer resp .Body .Close ()
107+ bodyBytes , err := io .ReadAll (resp .Body )
108+ if err != nil {
109+ t .Fatalf ("Failed to read response body: %s" , err )
110+ }
111+
112+ assert .Equal (t , http .StatusOK , resp .StatusCode )
113+ assert .Contains (t , string (bodyBytes ), "Przemyslaw" )
114+ assert .Contains (t , "Clickhouse" , resp .Header .Get ("X-Quesma-Source" ))
115+ }
116+
52117func (a * DualWriteAndCommonTableTestcase ) testIngestToClickHouseWorks (ctx context.Context , t * testing.T ) {
53118 resp , err := a .RequestToQuesma (ctx , "POST" , "/logs-2/_doc" , []byte (`{"name": "Przemyslaw", "age": 31337}` ))
54119 if err != nil {
0 commit comments