1 /*******************************************************************************
2 * Copyright (c) 2009, 2015 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Francois Chouinard - Initial API and implementation
11 * Francois Chouinard - Adapted for TMF Trace Model 1.0
12 * Alexandre Montplaisir - Port to JUnit4
13 * Marc-Andre Laperle - Adapted to CustomTxtTrace
14 *******************************************************************************/
16 package org
.eclipse
.tracecompass
.tmf
.core
.tests
.parsers
.custom
;
18 import java
.io
.BufferedWriter
;
20 import java
.io
.FileWriter
;
21 import java
.text
.SimpleDateFormat
;
22 import java
.util
.Date
;
24 import org
.eclipse
.tracecompass
.tmf
.core
.exceptions
.TmfTraceException
;
25 import org
.eclipse
.tracecompass
.tmf
.core
.parsers
.custom
.CustomTxtTrace
;
26 import org
.eclipse
.tracecompass
.tmf
.core
.parsers
.custom
.CustomTxtTraceDefinition
;
27 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceManager
;
28 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.indexer
.ITmfTraceIndexer
;
31 * Test suite for indexing using a CustomTxtTrace.
33 * @author Marc-Andre Laperle
35 public class CustomTxtIndexTest
extends AbstractCustomTraceIndexTest
{
37 private static final String TRACE_DIRECTORY
= TmfTraceManager
.getTemporaryDirPath() + File
.separator
+ "dummyTxtTrace";
38 private static final String TRACE_PATH
= TRACE_DIRECTORY
+ File
.separator
+ "test.txt";
39 private static final String DEFINITION_PATH
= "testfiles" + File
.separator
+ "txt" + File
.separator
+ "testTxtDefinition.xml";
41 private static CustomTxtTraceDefinition
createDefinition() {
42 CustomTxtTraceDefinition
[] definitions
= CustomTxtTraceDefinition
.loadAll(new File(DEFINITION_PATH
).toString());
43 return definitions
[0];
47 protected String
getTraceDirectory() {
48 return TRACE_DIRECTORY
;
52 protected TestTrace
createTrace() throws Exception
{
53 CustomTxtTraceDefinition definition
= createDefinition();
54 final File file
= new File(TRACE_PATH
);
55 try (BufferedWriter writer
= new BufferedWriter(new FileWriter(file
));) {
56 for (int i
= 0; i
< NB_EVENTS
; ++i
) {
57 SimpleDateFormat f
= new SimpleDateFormat(TIMESTAMP_FORMAT
);
58 String eventStr
= f
.format(new Date(i
)) + " hello world\n";
59 writer
.write(eventStr
);
63 return new TestTxtTrace(file
.toString(), definition
, BLOCK_SIZE
);
66 private class TestTxtTrace
extends CustomTxtTrace
implements TestTrace
{
67 public TestTxtTrace(String path
, CustomTxtTraceDefinition createDefinition
, int blockSize
) throws TmfTraceException
{
68 super(null, createDefinition
, path
, blockSize
);
72 protected ITmfTraceIndexer
createIndexer(int interval
) {
73 return new TestIndexer(this, interval
);
77 public TestIndexer
getIndexer() {
78 return (TestIndexer
) super.getIndexer();