1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
|
package integrationtests
import (
"context"
"fmt"
"path/filepath"
"testing"
)
func TestDMap1(t *testing.T) {
skipIfNotIntegrationTest(t)
cleanupTmpFiles(t)
testLogger := NewTestLogger("TestDMap1")
defer testLogger.WriteLogFile()
testTable := map[string]string{
"a": "from STATS select count($line),last($time)," +
"avg($goroutines),min(concurrentConnections),max(lifetimeConnections) " +
"group by $hostname",
"b": "from STATS select count($line),last($time)," +
"avg($goroutines),min(concurrentConnections),max(lifetimeConnections) " +
"group by $hostname where lifetimeConnections >= 3",
"c": "from STATS select count($line),last($time)," +
"avg($goroutines),min(concurrentConnections),max(lifetimeConnections) " +
"group by $hostname where $time eq \"1002-071949\"",
"d": "from STATS select $mask,$md5,$foo,$bar,$baz,last($time)," +
" set $mask = maskdigits($time), $md5 = md5sum($time), " +
"$foo = 42, $bar = \"baz\", $baz = $time group by $hostname",
}
// Test in serverless mode
t.Run("Serverless", func(t *testing.T) {
for subtestName, query := range testTable {
t.Run(subtestName, func(t *testing.T) {
t.Log("Testing dmap with input file")
testDmap1Serverless(t, testLogger, query, subtestName, false)
t.Log("Testing dmap with stdin input pipe")
testDmap1Serverless(t, testLogger, query, subtestName, true)
})
}
})
// Test in server mode
t.Run("ServerMode", func(t *testing.T) {
for subtestName, query := range testTable {
t.Run(subtestName, func(t *testing.T) {
t.Log("Testing dmap with input file in server mode")
testDmap1WithServer(t, testLogger, query, subtestName)
})
}
})
}
func testDmap1Serverless(t *testing.T, logger *TestLogger, query, subtestName string, usePipe bool) {
paths := GetStandardTestPaths()
csvFile := fmt.Sprintf("dmap1%s.csv.tmp", subtestName)
expectedCsvFile := fmt.Sprintf("dmap1%s.csv.expected", subtestName)
queryFile := fmt.Sprintf("%s.query", csvFile)
query = fmt.Sprintf("%s outfile %s", query, csvFile)
cleanupFiles(t, csvFile, queryFile)
ctxTimeout, cancel := createTestContextWithTimeout(t)
ctx := WithTestLogger(ctxTimeout, logger)
defer cancel()
var stdoutCh, stderrCh <-chan string
var cmdErrCh <-chan error
var err error
args := NewCommandArgs()
args.Logger = "stdout"
args.LogLevel = "info"
args.NoColor = true
args.ExtraArgs = []string{"--query", query}
if usePipe {
stdoutCh, stderrCh, cmdErrCh, err = startCommand(ctx, t,
paths.MaprTestData, "../dmap", args.ToSlice()...)
} else {
stdoutCh, stderrCh, cmdErrCh, err = startCommand(ctx, t,
"", "../dmap", append(args.ToSlice(), paths.MaprTestData)...)
}
if err != nil {
t.Error(err)
return
}
waitForCommand(ctx, t, stdoutCh, stderrCh, cmdErrCh)
if err := compareFilesContentsWithContext(ctx, t, csvFile, expectedCsvFile); err != nil {
t.Error(err)
}
if err := verifyQueryFile(t, queryFile, query); err != nil {
t.Error(err)
}
}
func testDmap1WithServer(t *testing.T, logger *TestLogger, query, subtestName string) {
ctx := WithTestLogger(context.Background(), logger)
paths := GetStandardTestPaths()
csvFile := fmt.Sprintf("dmap1%s.csv.tmp", subtestName)
expectedCsvFile := fmt.Sprintf("dmap1%s.csv.expected", subtestName)
queryFile := fmt.Sprintf("%s.query", csvFile)
query = fmt.Sprintf("%s outfile %s", query, csvFile)
cleanupFiles(t, csvFile, queryFile)
server := NewTestServer(t)
if err := server.Start("error"); err != nil {
t.Error(err)
return
}
args := NewCommandArgs()
args.Logger = "stdout"
args.LogLevel = "info"
args.NoColor = true
args.Servers = []string{server.Address()}
args.TrustAllHosts = true
args.Files = []string{paths.MaprTestData}
args.ExtraArgs = []string{"--query", query}
stdoutCh, stderrCh, cmdErrCh, err := startCommand(server.ctx, t,
"", "../dmap", args.ToSlice()...)
if err != nil {
t.Error(err)
return
}
waitForCommand(server.ctx, t, stdoutCh, stderrCh, cmdErrCh)
if err := compareFilesContentsWithContext(ctx, t, csvFile, expectedCsvFile); err != nil {
t.Error(err)
}
if err := verifyQueryFile(t, queryFile, query); err != nil {
t.Error(err)
}
}
func TestDMap2(t *testing.T) {
cleanupTmpFiles(t)
testLogger := NewTestLogger("TestDMap2")
defer testLogger.WriteLogFile()
runDualModeTest(t, DualModeTest{
Name: "TestDMap2",
ServerlessTest: func(t *testing.T) { testDMap2Serverless(t, testLogger) },
ServerTest: func(t *testing.T) { testDMap2WithServer(t, testLogger) },
})
}
func TestDMapOutfileArbitraryPath(t *testing.T) {
cleanupTmpFiles(t)
testLogger := NewTestLogger("TestDMapOutfileArbitraryPath")
defer testLogger.WriteLogFile()
runDualModeTest(t, DualModeTest{
Name: "TestDMapOutfileArbitraryPath",
ServerlessTest: func(t *testing.T) {
testDMapOutfileArbitraryPathServerless(t, testLogger)
},
ServerTest: func(t *testing.T) {
testDMapOutfileArbitraryPathWithServer(t, testLogger)
},
})
}
func testDMapOutfileArbitraryPathServerless(t *testing.T, logger *TestLogger) {
paths := GetStandardTestPaths()
outFile := "dmap_outfile_arbitrary_serverless.stdout.tmp"
csvFile := filepath.Join(t.TempDir(), "dmap_outfile_arbitrary_serverless.csv")
expectedCsvFile := "dmap2.csv.expected"
queryFile := fmt.Sprintf("%s.query", csvFile)
query := fmt.Sprintf("from STATS select count($time),$time,max($goroutines),"+
"avg($goroutines),min($goroutines) group by $time order by count($time) "+
"outfile %s", csvFile)
if !filepath.IsAbs(csvFile) {
t.Fatalf("expected absolute outfile path, got %q", csvFile)
}
cleanupFiles(t, outFile, csvFile, queryFile)
ctxTimeout, cancel := createTestContextWithTimeout(t)
ctx := WithTestLogger(ctxTimeout, logger)
defer cancel()
_, err := runCommand(ctx, t, outFile,
"../dmap", "--query", query, "--cfg", "none", paths.MaprTestData)
if err != nil {
t.Error(err)
return
}
if err := compareFilesContentsWithContext(ctx, t, csvFile, expectedCsvFile); err != nil {
t.Error(err)
}
if err := verifyQueryFile(t, queryFile, query); err != nil {
t.Error(err)
}
}
func testDMapOutfileArbitraryPathWithServer(t *testing.T, logger *TestLogger) {
ctx := WithTestLogger(context.Background(), logger)
paths := GetStandardTestPaths()
outFile := "dmap_outfile_arbitrary_server.stdout.tmp"
csvFile := filepath.Join(t.TempDir(), "dmap_outfile_arbitrary_server.csv")
expectedCsvFile := "dmap2.csv.expected"
queryFile := fmt.Sprintf("%s.query", csvFile)
query := fmt.Sprintf("from STATS select count($time),$time,max($goroutines),"+
"avg($goroutines),min($goroutines) group by $time order by count($time) "+
"outfile %s", csvFile)
if !filepath.IsAbs(csvFile) {
t.Fatalf("expected absolute outfile path, got %q", csvFile)
}
cleanupFiles(t, outFile, csvFile, queryFile)
server := NewTestServer(t)
if err := server.Start("error"); err != nil {
t.Error(err)
return
}
args := NewCommandArgs()
args.Servers = []string{server.Address()}
args.TrustAllHosts = true
args.NoColor = true
args.Files = []string{paths.MaprTestData}
args.ExtraArgs = []string{"--query", query}
_, err := runCommand(server.ctx, t, outFile,
"../dmap", args.ToSlice()...)
if err != nil {
t.Error(err)
return
}
if err := compareFilesContentsWithContext(ctx, t, csvFile, expectedCsvFile); err != nil {
t.Error(err)
}
if err := verifyQueryFile(t, queryFile, query); err != nil {
t.Error(err)
}
}
func testDMap2Serverless(t *testing.T, logger *TestLogger) {
paths := GetStandardTestPaths()
outFile := "dmap2_serverless.stdout.tmp"
csvFile := "dmap2_serverless.csv.tmp"
expectedCsvFile := "dmap2.csv.expected"
queryFile := fmt.Sprintf("%s.query", csvFile)
cleanupFiles(t, outFile, csvFile, queryFile)
query := fmt.Sprintf("from STATS select count($time),$time,max($goroutines),"+
"avg($goroutines),min($goroutines) group by $time order by count($time) "+
"outfile %s", csvFile)
ctxTimeout, cancel := createTestContextWithTimeout(t)
ctx := WithTestLogger(ctxTimeout, logger)
defer cancel()
_, err := runCommand(ctx, t, outFile,
"../dmap", "--query", query, "--cfg", "none", paths.MaprTestData)
if err != nil {
t.Error(err)
return
}
if err := compareFilesContentsWithContext(ctx, t, csvFile, expectedCsvFile); err != nil {
t.Error(err)
}
if err := verifyQueryFile(t, queryFile, query); err != nil {
t.Error(err)
}
}
func testDMap2WithServer(t *testing.T, logger *TestLogger) {
ctx := WithTestLogger(context.Background(), logger)
paths := GetStandardTestPaths()
outFile := "dmap2_server.stdout.tmp"
csvFile := "dmap2_server.csv.tmp"
expectedCsvFile := "dmap2.csv.expected"
queryFile := fmt.Sprintf("%s.query", csvFile)
cleanupFiles(t, outFile, csvFile, queryFile)
server := NewTestServer(t)
if err := server.Start("error"); err != nil {
t.Error(err)
return
}
query := fmt.Sprintf("from STATS select count($time),$time,max($goroutines),"+
"avg($goroutines),min($goroutines) group by $time order by count($time) "+
"outfile %s", csvFile)
args := NewCommandArgs()
args.Servers = []string{server.Address()}
args.TrustAllHosts = true
args.NoColor = true
args.Files = []string{paths.MaprTestData}
args.ExtraArgs = []string{"--query", query}
_, err := runCommand(server.ctx, t, outFile,
"../dmap", args.ToSlice()...)
if err != nil {
t.Error(err)
return
}
if err := compareFilesContentsWithContext(ctx, t, csvFile, expectedCsvFile); err != nil {
t.Error(err)
}
if err := verifyQueryFile(t, queryFile, query); err != nil {
t.Error(err)
}
}
func TestDMap3(t *testing.T) {
cleanupTmpFiles(t)
testLogger := NewTestLogger("TestDMap3")
defer testLogger.WriteLogFile()
runDualModeTest(t, DualModeTest{
Name: "TestDMap3",
ServerlessTest: func(t *testing.T) { testDMap3Serverless(t, testLogger) },
ServerTest: func(t *testing.T) { testDMap3WithServer(t, testLogger) },
})
}
func testDMap3Serverless(t *testing.T, logger *TestLogger) {
paths := GetStandardTestPaths()
outFile := "dmap3_serverless.stdout.tmp"
csvFile := "dmap3_serverless.csv.tmp"
expectedCsvFile := "dmap3.csv.expected"
queryFile := fmt.Sprintf("%s.query", csvFile)
cleanupFiles(t, outFile, csvFile, queryFile)
query := fmt.Sprintf("from STATS select count($time),$time,max($goroutines),avg($goroutines),min($goroutines) "+
"group by $time order by count($time) desc "+
"outfile %s", csvFile)
// Create a large list of input files
var inputFiles []string
for i := 0; i < 100; i++ {
inputFiles = append(inputFiles, paths.MaprTestData)
}
// Simply run dmap with multiple input files directly
// Use longer timeout for processing 100 files
ctxTimeout, cancel := createTestContextWithLongTimeout(t)
ctx := WithTestLogger(ctxTimeout, logger)
defer cancel()
args := NewCommandArgs()
args.ExtraArgs = []string{"--query", query}
_, err := runCommand(ctx, t, outFile,
"../dmap", append(args.ToSlice(), inputFiles...)...)
if err != nil {
t.Error(err)
return
}
if err := compareFilesContentsWithContext(ctx, t, csvFile, expectedCsvFile); err != nil {
t.Error(err)
}
if err := verifyQueryFile(t, queryFile, query); err != nil {
t.Error(err)
}
}
func testDMap3WithServer(t *testing.T, logger *TestLogger) {
ctx := WithTestLogger(context.Background(), logger)
paths := GetStandardTestPaths()
outFile := "dmap3_server.stdout.tmp"
csvFile := "dmap3_server.csv.tmp"
expectedCsvFile := "dmap3.csv.expected"
queryFile := fmt.Sprintf("%s.query", csvFile)
cleanupFiles(t, outFile, csvFile, queryFile)
server := NewTestServer(t)
// Use optimized config for processing 100 files
cfg := &ServerConfig{
Port: server.port,
BindAddress: server.bindAddress,
LogLevel: "error",
ExtraArgs: []string{"--cfg", "test_server_100files.json"},
Env: map[string]string{"DTAIL_TURBOBOOST_ENABLE": "yes"},
}
if err := server.StartWithConfig(cfg); err != nil {
t.Error(err)
return
}
query := fmt.Sprintf("from STATS select count($time),$time,max($goroutines),avg($goroutines),min($goroutines) "+
"group by $time order by count($time) desc "+
"outfile %s", csvFile)
// Create a large list of input files
var inputFiles []string
for i := 0; i < 100; i++ {
inputFiles = append(inputFiles, paths.MaprTestData)
}
args := NewCommandArgs()
args.Servers = []string{server.Address()}
args.TrustAllHosts = true
args.NoColor = true
args.Files = inputFiles
args.ExtraArgs = []string{"--query", query}
_, err := runCommand(server.ctx, t, outFile,
"../dmap", args.ToSlice()...)
if err != nil {
t.Error(err)
return
}
if err := compareFilesContentsWithContext(ctx, t, csvFile, expectedCsvFile); err != nil {
t.Error(err)
}
if err := verifyQueryFile(t, queryFile, query); err != nil {
t.Error(err)
}
}
func TestDMap4Append(t *testing.T) {
cleanupTmpFiles(t)
testLogger := NewTestLogger("TestDMap4Append")
defer testLogger.WriteLogFile()
runDualModeTest(t, DualModeTest{
Name: "TestDMap4Append",
ServerlessTest: func(t *testing.T) { testDMap4AppendServerless(t, testLogger) },
ServerTest: func(t *testing.T) { testDMap4AppendWithServer(t, testLogger) },
})
}
func testDMap4AppendServerless(t *testing.T, logger *TestLogger) {
paths := GetStandardTestPaths()
csvFile := "dmap4_serverless.csv.tmp"
queryFile := fmt.Sprintf("%s.query", csvFile)
// Clean up files once at the beginning
cleanupFiles(t, csvFile, queryFile)
t.Run("FirstQuery", func(t *testing.T) {
stdout := "dmap4_serverless.stdout1.tmp"
cleanupFiles(t, stdout)
// First query
query := fmt.Sprintf("from STATS select count($time),$time,max($goroutines),"+
"avg($goroutines),min($goroutines) group by $time order by count($time) "+
"outfile %s", csvFile)
ctx, cancel := createTestContextWithTimeout(t)
defer cancel()
_, err := runCommand(ctx, t, stdout,
"../dmap", "--query", query, "--cfg", "none", paths.MaprTestData)
if err != nil {
t.Error(err)
return
}
// Verify the CSV output
if err := compareFilesContentsWithContext(ctx, t, csvFile, "dmap4_query1.csv.expected"); err != nil {
t.Error(err)
}
// Verify the query file
if err := verifyQueryFile(t, queryFile, query); err != nil {
t.Error(err)
}
})
t.Run("SecondQueryWithAppend", func(t *testing.T) {
stdout := "dmap4_serverless.stdout2.tmp"
cleanupFiles(t, stdout)
// Second query with append
query := fmt.Sprintf("from STATS select count($time),$time,max($goroutines),"+
"avg($goroutines),min($goroutines) group by $time order by avg($goroutines) reverse "+
"outfile append:%s", csvFile)
ctx, cancel := createTestContextWithTimeout(t)
defer cancel()
_, err := runCommand(ctx, t, stdout,
"../dmap", "--query", query, "--cfg", "none", paths.MaprTestData)
if err != nil {
t.Error(err)
return
}
// Verify the CSV output (should still be the first query result - append doesn't change existing file)
if err := compareFilesContentsWithContext(ctx, t, csvFile, "dmap4_query1.csv.expected"); err != nil {
t.Error(err)
}
})
t.Run("ThirdQueryWithAppend", func(t *testing.T) {
stdout := "dmap4_serverless.stdout3.tmp"
cleanupFiles(t, stdout)
// Third query with append (different structure)
query := fmt.Sprintf("from STATS select count($line),$hostname "+
"group by $hostname "+
"outfile append:%s", csvFile)
ctx, cancel := createTestContextWithTimeout(t)
defer cancel()
_, err := runCommand(ctx, t, stdout,
"../dmap", "--query", query, "--cfg", "none", paths.MaprTestData)
if err != nil {
t.Error(err)
return
}
// Verify the CSV output (should still be the first query result - append doesn't change existing file)
if err := compareFilesContentsWithContext(ctx, t, csvFile, "dmap4_query1.csv.expected"); err != nil {
t.Error(err)
}
// For append test, the query file should still contain the first query
firstQuery := fmt.Sprintf("from STATS select count($time),$time,max($goroutines),"+
"avg($goroutines),min($goroutines) group by $time order by count($time) "+
"outfile %s", csvFile)
if err := verifyQueryFile(t, queryFile, firstQuery); err != nil {
t.Error(err)
}
})
}
func testDMap4AppendWithServer(t *testing.T, logger *TestLogger) {
ctx := WithTestLogger(context.Background(), logger)
paths := GetStandardTestPaths()
csvFile := "dmap4_server.csv.tmp"
queryFile := fmt.Sprintf("%s.query", csvFile)
server := NewTestServer(t)
if err := server.Start("error"); err != nil {
t.Error(err)
return
}
baseArgs := NewCommandArgs()
baseArgs.Servers = []string{server.Address()}
baseArgs.TrustAllHosts = true
baseArgs.NoColor = true
baseArgs.Files = []string{paths.MaprTestData}
// Clean up files once at the beginning
cleanupFiles(t, csvFile, queryFile)
t.Run("FirstQuery", func(t *testing.T) {
stdout := "dmap4_server.stdout1.tmp"
cleanupFiles(t, stdout)
// First query
query := fmt.Sprintf("from STATS select count($time),$time,max($goroutines),"+
"avg($goroutines),min($goroutines) group by $time order by count($time) "+
"outfile %s", csvFile)
args := *baseArgs
args.ExtraArgs = []string{"--query", query}
_, err := runCommand(server.ctx, t, stdout,
"../dmap", args.ToSlice()...)
if err != nil {
t.Error(err)
return
}
// Verify the CSV output
if err := compareFilesContentsWithContext(ctx, t, csvFile, "dmap4_query1.csv.expected"); err != nil {
t.Error(err)
}
// Verify the query file
if err := verifyQueryFile(t, queryFile, query); err != nil {
t.Error(err)
}
})
t.Run("SecondQueryWithAppend", func(t *testing.T) {
stdout := "dmap4_server.stdout2.tmp"
cleanupFiles(t, stdout)
// Second query with append
query := fmt.Sprintf("from STATS select count($time),$time,max($goroutines),"+
"avg($goroutines),min($goroutines) group by $time order by avg($goroutines) reverse "+
"outfile append:%s", csvFile)
args := *baseArgs
args.ExtraArgs = []string{"--query", query}
_, err := runCommand(server.ctx, t, stdout,
"../dmap", args.ToSlice()...)
if err != nil {
t.Error(err)
return
}
// Verify the CSV output (should still be the first query result - append doesn't change existing file)
if err := compareFilesContentsWithContext(ctx, t, csvFile, "dmap4_query1.csv.expected"); err != nil {
t.Error(err)
}
})
t.Run("ThirdQueryWithAppend", func(t *testing.T) {
stdout := "dmap4_server.stdout3.tmp"
cleanupFiles(t, stdout)
// Third query with append (different structure)
query := fmt.Sprintf("from STATS select count($line),$hostname "+
"group by $hostname "+
"outfile append:%s", csvFile)
args := *baseArgs
args.ExtraArgs = []string{"--query", query}
_, err := runCommand(server.ctx, t, stdout,
"../dmap", args.ToSlice()...)
if err != nil {
t.Error(err)
return
}
// Verify the CSV output (should still be the first query result - append doesn't change existing file)
if err := compareFilesContentsWithContext(ctx, t, csvFile, "dmap4_query1.csv.expected"); err != nil {
t.Error(err)
}
// For append test, the query file should still contain the first query
firstQuery := fmt.Sprintf("from STATS select count($time),$time,max($goroutines),"+
"avg($goroutines),min($goroutines) group by $time order by count($time) "+
"outfile %s", csvFile)
if err := verifyQueryFile(t, queryFile, firstQuery); err != nil {
t.Error(err)
}
})
}
func TestDMap5CSV(t *testing.T) {
cleanupTmpFiles(t)
testLogger := NewTestLogger("TestDMap5CSV")
defer testLogger.WriteLogFile()
runDualModeTest(t, DualModeTest{
Name: "TestDMap5CSV",
ServerlessTest: func(t *testing.T) { testDMap5CSVServerless(t, testLogger) },
ServerTest: func(t *testing.T) { testDMap5CSVWithServer(t, testLogger) },
})
}
func testDMap5CSVServerless(t *testing.T, logger *TestLogger) {
inFile := "dmap5.csv.in"
csvFile := "dmap5_serverless.csv.tmp"
expectedCsvFile := "dmap5.csv.expected"
queryFile := fmt.Sprintf("%s.query", csvFile)
outFile := "dmap5_serverless.stdout.tmp"
cleanupFiles(t, csvFile, queryFile, outFile)
query := fmt.Sprintf("select sum($timecount),last($time),min($min_goroutines) "+
"group by $hostname set $timecount = `count($time)`, $time = `$time`, "+
"$min_goroutines = `min($goroutines)` logformat csv outfile %s", csvFile)
ctxTimeout, cancel := createTestContextWithTimeout(t)
ctx := WithTestLogger(ctxTimeout, logger)
defer cancel()
_, err := runCommand(ctx, t, outFile,
"../dmap", "--query", query, "--cfg", "none", inFile)
if err != nil {
t.Error(err)
return
}
if err := compareFilesContentsWithContext(ctx, t, csvFile, expectedCsvFile); err != nil {
t.Error(err)
}
// Verify the query file contains the expected query
if err := verifyQueryFile(t, queryFile, query); err != nil {
t.Error(err)
}
}
func testDMap5CSVWithServer(t *testing.T, logger *TestLogger) {
ctx := WithTestLogger(context.Background(), logger)
inFile := "dmap5.csv.in"
csvFile := "dmap5_server.csv.tmp"
expectedCsvFile := "dmap5.csv.expected"
queryFile := fmt.Sprintf("%s.query", csvFile)
outFile := "dmap5_server.stdout.tmp"
cleanupFiles(t, csvFile, queryFile, outFile)
server := NewTestServer(t)
if err := server.Start("error"); err != nil {
t.Error(err)
return
}
query := fmt.Sprintf("select sum($timecount),last($time),min($min_goroutines) "+
"group by $hostname set $timecount = `count($time)`, $time = `$time`, "+
"$min_goroutines = `min($goroutines)` logformat csv outfile %s", csvFile)
args := NewCommandArgs()
args.Servers = []string{server.Address()}
args.TrustAllHosts = true
args.NoColor = true
args.Files = []string{inFile}
args.ExtraArgs = []string{"--query", query}
_, err := runCommand(server.ctx, t, outFile,
"../dmap", args.ToSlice()...)
if err != nil {
t.Error(err)
return
}
if err := compareFilesContentsWithContext(ctx, t, csvFile, expectedCsvFile); err != nil {
t.Error(err)
}
// Verify the query file contains the expected query
if err := verifyQueryFile(t, queryFile, query); err != nil {
t.Error(err)
}
}
|