001: /*
002: * MCS Media Computer Software Copyright (c) 2005 by MCS
003: * -------------------------------------- Created on 23.04.2005 by w.klaas
004: *
005: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
006: * use this file except in compliance with the License. You may obtain a copy of
007: * the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
013: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
014: * License for the specific language governing permissions and limitations under
015: * the License.
016: */
017: package de.mcs.jmeasurement.test;
018:
019: import junit.framework.TestCase;
020: import de.mcs.jmeasurement.MeasureFactory;
021: import de.mcs.jmeasurement.MeasurementException;
022: import de.mcs.jmeasurement.Monitor;
023:
024: public class AutoSavingsTest extends TestCase {
025:
026: private static final String BASEPOINT = "de.mcs.jmeasurement.test";
027:
028: private static final String APPNAME = "de.mcs.jmeasurement.test.Application";
029:
030: public void testStart() throws InterruptedException,
031: MeasurementException {
032: MeasureFactory.setApplicationName(APPNAME);
033: assertEquals(APPNAME, MeasureFactory.getApplicationName());
034:
035: // HashMap<String, String> aOptions = new HashMap<String, String>();
036: // aOptions.put(JMConfig.OPTION_BACKGROUND_TIME, Long.toString(60000));
037: // aOptions.put(JMConfig.OPTION_ENABLE_AUTOSNAPSHOT, Boolean
038: // .toString(true));
039: // aOptions.put(JMConfig.OPTION_ENABLE_MEMORY_SAVINGS, Boolean
040: // .toString(true));
041: // aOptions.put(JMConfig.OPTION_POINT_IDLETIME, Long.toString(60000));
042: //
043: // aOptions.put(JMConfig.OPTION_WORKINGPATH, "e:\\temp\\data\\");
044: //
045: MeasureFactory.configure();
046: // MeasureFactory.setOptions(aOptions);
047: // MeasureFactory.setExceptionHandling(JMConfig.EXCEPTION_TRACE);
048:
049: outMem();
050: Monitor[] monitors = new Monitor[1000];
051: for (int i = 0; i < monitors.length; i++) {
052: Monitor monitor = MeasureFactory.start(BASEPOINT + "."
053: + Integer.toString(i));
054: monitors[i] = monitor;
055: }
056: Thread.sleep(100);
057: for (int i = 0; i < monitors.length; i++) {
058: Monitor monitor2 = null;
059: try {
060: monitor2.decrease(100);
061: } catch (Exception e) {
062: monitors[i].setException(e);
063: }
064: }
065: for (int i = 0; i < monitors.length; i++) {
066: Monitor monitor = MeasureFactory.start(BASEPOINT + "."
067: + Integer.toString(i));
068: monitors[i] = monitor;
069: }
070: Thread.sleep(100);
071: for (int i = 0; i < monitors.length; i++) {
072: Monitor monitor2 = null;
073: try {
074: monitor2.decrease(100);
075: } catch (Exception e) {
076: monitors[i].setException(e);
077: }
078: }
079:
080: System.out.println("now waiting for 2 minutes.");
081: System.gc();
082: System.gc();
083: outMem();
084: Thread.sleep(1000 * 60);
085: System.out.println("now the savings must happen.");
086: Thread.sleep(1000 * 10);
087: outMem();
088: System.out.println("System.gc()");
089: System.gc();
090: System.gc();
091: outMem();
092: MeasureFactory.asString();
093: System.out.println("after reload");
094: outMem();
095: }
096:
097: private void outMem() {
098: System.out.println("FREEMEMORY: "
099: + Long.toString(Runtime.getRuntime().freeMemory()));
100: System.out.println("MAXMEMORY: "
101: + Long.toString(Runtime.getRuntime().maxMemory()));
102: System.out.println("TOTALMEMORY:"
103: + Long.toString(Runtime.getRuntime().totalMemory()));
104:
105: }
106: // 779624
107: // 2463720
108: }
|