jdk/test/java/util/logging/FileHandlerLongLimit.java
changeset 29117 7956b5dc0eac
parent 27191 45a3002de56f
child 30046 cf2c86e1819e
equal deleted inserted replaced
29116:9918719cfcc0 29117:7956b5dc0eac
     1 /*
     1 /*
     2  * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
   344 
   344 
   345             // check that fh.meter.written is 0
   345             // check that fh.meter.written is 0
   346             assertEquals(0, getWritten(metered), "written");
   346             assertEquals(0, getWritten(metered), "written");
   347 
   347 
   348             // now we're going to publish a series of log records
   348             // now we're going to publish a series of log records
       
   349             // we're using the same log record over and over to make
       
   350             // sure we get the same amount of bytes.
   349             String msg = "this is at least 10 chars long";
   351             String msg = "this is at least 10 chars long";
   350             fh.publish(new LogRecord(Level.SEVERE, msg));
   352             LogRecord record = new LogRecord(Level.SEVERE, msg);
       
   353             fh.publish(record);
   351             fh.flush();
   354             fh.flush();
   352             long w = getWritten(metered);
   355             long w = getWritten(metered);
   353             long offset = getWritten(metered);
   356             long offset = getWritten(metered);
   354             System.out.println("first offset is:  " + offset);
   357             System.out.println("first offset is:  " + offset);
   355 
   358 
   356             fh.publish(new LogRecord(Level.SEVERE, msg));
   359             fh.publish(record);
   357             fh.flush();
   360             fh.flush();
   358             offset = getWritten(metered) - w;
   361             offset = getWritten(metered) - w;
   359             w = getWritten(metered);
   362             w = getWritten(metered);
   360             System.out.println("second offset is: " + offset);
   363             System.out.println("second offset is: " + offset);
   361 
   364 
   362             fh.publish(new LogRecord(Level.SEVERE, msg));
   365             fh.publish(record);
   363             fh.flush();
   366             fh.flush();
   364             offset = getWritten(metered) - w;
   367             offset = getWritten(metered) - w;
   365             w = getWritten(metered);
   368             w = getWritten(metered);
   366             System.out.println("third offset is:  " + offset);
   369             System.out.println("third offset is:  " + offset);
   367 
   370 
   368             fh.publish(new LogRecord(Level.SEVERE, msg));
   371             fh.publish(record);
   369             fh.flush();
   372             fh.flush();
   370             offset = getWritten(metered) - w;
   373             offset = getWritten(metered) - w;
   371             System.out.println("fourth offset is: " + offset);
   374             System.out.println("fourth offset is: " + offset);
   372 
   375 
   373             // Now set fh.meter.written to something close to the limit,
   376             // Now set fh.meter.written to something close to the limit,
   375             assertEquals(limit-2*offset+10, setWritten(metered, limit-2*offset+10), "written");
   378             assertEquals(limit-2*offset+10, setWritten(metered, limit-2*offset+10), "written");
   376             w = getWritten(metered);
   379             w = getWritten(metered);
   377 
   380 
   378             // publish one more log record. we should still be just beneath
   381             // publish one more log record. we should still be just beneath
   379             // the limit
   382             // the limit
   380             fh.publish(new LogRecord(Level.SEVERE, msg));
   383             fh.publish(record);
   381             fh.flush();
   384             fh.flush();
   382             assertEquals(w+offset, getWritten(metered), "written");
   385             assertEquals(w+offset, getWritten(metered), "written");
   383 
   386 
   384             // check that fh still has the same MeteredStream - indicating
   387             // check that fh still has the same MeteredStream - indicating
   385             // that the file hasn't rotated.
   388             // that the file hasn't rotated.
   390             // Now publish two log record. The spec is a bit vague about when
   393             // Now publish two log record. The spec is a bit vague about when
   391             // exactly the log will be rotated - it could happen just after
   394             // exactly the log will be rotated - it could happen just after
   392             // writing the first log record or just before writing the next
   395             // writing the first log record or just before writing the next
   393             // one. We publich two - so we're sure that the log must have
   396             // one. We publich two - so we're sure that the log must have
   394             // rotated.
   397             // rotated.
   395             fh.publish(new LogRecord(Level.SEVERE, msg));
   398             fh.publish(record);
   396             fh.flush();
   399             fh.flush();
   397             fh.publish(new LogRecord(Level.SEVERE, msg));
   400             fh.publish(record);
   398             fh.flush();
   401             fh.flush();
   399 
   402 
   400             // Check that fh.meter is a different instance of MeteredStream.
   403             // Check that fh.meter is a different instance of MeteredStream.
   401             if (getMeteredOutput(fh) == metered) {
   404             if (getMeteredOutput(fh) == metered) {
   402                 throw new RuntimeException("Log should have rotated");
   405                 throw new RuntimeException("Log should have rotated");