001: /*
002: * MCS Media Computer Software
003: * Copyright (c) 2005 by MCS
004: * --------------------------------------
005: * Created on 23.04.2005 by w.klaas
006: *
007: * Licensed under the Apache License, Version 2.0 (the "License");
008: * you may not use this file except in compliance with the License.
009: * You may obtain a copy of the License at
010: *
011: * http://www.apache.org/licenses/LICENSE-2.0
012: *
013: * Unless required by applicable law or agreed to in writing, software
014: * distributed under the License is distributed on an "AS IS" BASIS,
015: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016: * See the License for the specific language governing permissions and
017: * limitations under the License.
018: */
019: package de.mcs.jmeasurement.test;
020:
021: import java.io.IOException;
022: import java.util.Random;
023:
024: import de.mcs.jmeasurement.MeasureDataCallback;
025: import de.mcs.jmeasurement.MeasureFactory;
026: import de.mcs.jmeasurement.MeasurePoint;
027: import de.mcs.jmeasurement.MeasurementException;
028: import de.mcs.jmeasurement.Monitor;
029: import de.mcs.jmeasurement.example.DataPointStore;
030: import de.mcs.jmeasurement.example.IncrementTime100;
031: import de.mcs.jmeasurement.example.UserDataStore;
032: import de.mcs.utils.Files;
033:
034: /**
035: * @author w.klaas
036: */
037: public class UserDataStoreTest extends MCSTestCase {
038:
039: private static final String BASEPOINT = "de.mcs.jmeasurement.test";
040:
041: private static final String BASEPOINT1 = BASEPOINT + ".1";
042:
043: private static final String BASEPOINT2 = BASEPOINT + ".2";
044:
045: public void testUserDataStore() throws InterruptedException,
046: MeasurementException {
047: MeasureFactory.clear();
048: MeasureFactory.setPriority(0);
049: MeasureDataCallback callback = new IncrementTime100();
050: MeasureFactory.setMeasureDataCallback(callback);
051:
052: assertEquals(callback, MeasureFactory.getMeasureDataCallback());
053:
054: MeasurePoint point1 = MeasureFactory
055: .getMeasurePoint(BASEPOINT1);
056: MeasurePoint point2 = MeasureFactory
057: .getMeasurePoint(BASEPOINT2);
058:
059: String datafile1 = null;
060: String datafile2 = null;
061: try {
062: datafile1 = Files.getTempPath() + BASEPOINT1 + ".log";
063: datafile2 = Files.getTempPath() + BASEPOINT2 + ".log";
064: } catch (IOException e) {
065: // TODO Auto-generated catch block
066: e.printStackTrace();
067: }
068: UserDataStore userDataStore1 = new UserDataStore(101, datafile1);
069: userDataStore1.setSepChar(';');
070: UserDataStore userDataStore2 = new UserDataStore(101, datafile2);
071: userDataStore2.setSepChar(',');
072: point1.setUserData(userDataStore1);
073: point2.setUserData(userDataStore2);
074:
075: DataPointStore dataToFile = new DataPointStore();
076:
077: point1.setMeasureDataCallback(dataToFile);
078: point2.setMeasureDataCallback(dataToFile);
079:
080: assertEquals(dataToFile, point1.getMeasureDataCallback());
081:
082: Monitor monitor1;
083: Monitor monitor2;
084: Random random = new Random();
085: for (int i = 0; i < 100; i++) {
086: monitor1 = MeasureFactory.start(BASEPOINT1);
087: monitor2 = MeasureFactory.start(BASEPOINT2);
088: Thread.sleep(random.nextInt(101));
089: monitor1.stop();
090: monitor2.stop();
091: }
092: System.out.println("----------");
093: System.out.println("testUserDataStore");
094: System.out.println("point1:");
095: String[] datas = userDataStore1.getData();
096: for (int i = 0; i < datas.length; i++) {
097: String string = datas[i];
098: System.out.println(string);
099: }
100: System.out.println("point2:");
101: datas = userDataStore2.getData();
102: for (int i = 0; i < datas.length; i++) {
103: String string = datas[i];
104: System.out.println(string);
105: }
106:
107: ((UserDataStore) point1.getUserData()).closeFile();
108: ((UserDataStore) point2.getUserData()).closeFile();
109: System.out
110: .println("please control the following files manually.");
111: System.out.println("file1:" + datafile1);
112: System.out.println("file2:" + datafile2);
113: }
114: }
|