Commit | Line | Data |
---|---|---|
d18dd09b | 1 | /******************************************************************************* |
61759503 | 2 | * Copyright (c) 2009, 2012 Ericsson |
0283f7ff | 3 | * |
d18dd09b ASL |
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 | |
0283f7ff | 8 | * |
d18dd09b | 9 | * Contributors: |
165c977c | 10 | * Francois Chouinard - Initial API and implementation |
d18dd09b ASL |
11 | *******************************************************************************/ |
12 | ||
4918b8f2 | 13 | package org.eclipse.linuxtools.tmf.tests.stubs; |
d18dd09b ASL |
14 | |
15 | import java.io.BufferedOutputStream; | |
16 | import java.io.DataOutputStream; | |
165c977c | 17 | import java.io.File; |
d18dd09b ASL |
18 | import java.io.FileNotFoundException; |
19 | import java.io.FileOutputStream; | |
20 | import java.io.IOException; | |
165c977c | 21 | import java.util.Random; |
d18dd09b ASL |
22 | |
23 | /** | |
24 | * <b><u>CreateTestFiles</u></b> | |
25 | * <p> | |
26 | * Create a number of event test files of various lengths. | |
27 | * <p> | |
28 | * Events have the following format: | |
29 | * <ul> | |
30 | * <li> [timestamp] [source] [type] [ref] [field]* | |
31 | * <li> There are NB_SOURCES sources and NB_TYPES types. | |
32 | * <li> The number of fields (0 .. NB_TYPES-1) depends on the event type. | |
33 | * </ul> | |
34 | */ | |
35 | public class CreateTestFiles { | |
36 | ||
37 | // ======================================================================== | |
38 | // Constants | |
39 | // ======================================================================== | |
40 | ||
085d898f FC |
41 | private static final String DIRECTORY = "testfiles"; |
42 | // private static final String FILE_NAMES[] = { "Test-10", "Test-1K", "Test-10K", "Test-100K" }; | |
43 | // private static final int FILE_SIZES[] = { 10 , 1000 , 10000 , 100000 }; | |
44 | private static final String FILE_NAMES[] = { "Test-10K" }; | |
85fb0e54 | 45 | private static final int FILE_SIZES[] = { 10000 }; |
d18dd09b | 46 | |
085d898f FC |
47 | private static final int NB_SOURCES = 15; |
48 | private static final int NB_TYPES = 7; | |
d18dd09b ASL |
49 | |
50 | // ======================================================================== | |
51 | // Constructors | |
52 | // ======================================================================== | |
53 | ||
085d898f | 54 | /** |
0283f7ff | 55 | * @param args unused |
d18dd09b | 56 | */ |
085d898f FC |
57 | public static void main(final String[] args) { |
58 | ||
165c977c | 59 | try { |
50adc88e | 60 | System.out.println("Creating test files in directory: " + new File(".").getCanonicalPath() + File.separator + DIRECTORY); |
085d898f | 61 | } catch (final IOException e) { |
165c977c FC |
62 | e.printStackTrace(); |
63 | } | |
64 | ||
0283f7ff | 65 | for (int i = 0; i < FILE_SIZES.length; i++) { |
d18dd09b | 66 | try { |
085d898f FC |
67 | createTestFile("testfiles" + File.separator + "O-" + FILE_NAMES[i], FILE_SIZES[i], true, true); |
68 | createTestFile("testfiles" + File.separator + "E-" + FILE_NAMES[i], FILE_SIZES[i], true, false); | |
85fb0e54 | 69 | createTestFile("testfiles" + File.separator + "R-" + FILE_NAMES[i], FILE_SIZES[i], false, false); |
085d898f FC |
70 | } catch (final FileNotFoundException e) { |
71 | } catch (final IOException e) { | |
d18dd09b | 72 | } |
0283f7ff | 73 | } |
165c977c | 74 | |
085d898f | 75 | System.out.println("Done."); |
d18dd09b ASL |
76 | } |
77 | ||
78 | // ======================================================================== | |
79 | // Operators | |
80 | // ======================================================================== | |
81 | ||
82 | /** | |
83 | * @param file | |
84 | * @param size | |
165c977c | 85 | * @param monotonic |
d18dd09b ASL |
86 | * @throws FileNotFoundException |
87 | * @throws IOException | |
88 | */ | |
085d898f | 89 | private static void createTestFile(final String file, final int size, final boolean monotonic, final boolean odd) throws FileNotFoundException, IOException { |
d18dd09b ASL |
90 | DataOutputStream out; |
91 | System.out.println("Creating " + file); | |
92 | out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file))); | |
93 | ||
085d898f | 94 | final Random generator = new Random(19580427 + size); |
85fb0e54 | 95 | long ts = (monotonic && odd) ? -1 : 0; |
d18dd09b | 96 | for (int i = 0; i < size; i++) { |
85fb0e54 | 97 | ts += monotonic ? 2 : generator.nextInt(10); |
085d898f FC |
98 | final int sourceIndex = i % NB_SOURCES; |
99 | final int typeIndex = i % NB_TYPES; | |
165c977c | 100 | out.writeLong(ts); // Timestamp |
d18dd09b ASL |
101 | out.writeUTF("Source-" + sourceIndex); // Source |
102 | out.writeUTF("Type-" + typeIndex); // Type | |
165c977c | 103 | out.writeInt(i + 1); // Reference (event #) |
0283f7ff | 104 | for (int j = 0; j < typeIndex; j++) { |
d18dd09b | 105 | out.writeUTF("Field-" + sourceIndex + "-" + j); |
0283f7ff | 106 | } |
d18dd09b ASL |
107 | } |
108 | out.flush(); | |
109 | out.close(); | |
110 | } | |
165c977c | 111 | |
d18dd09b | 112 | } |