Path: blob/master/test/jdk/sun/rmi/log/ReliableLog/SnapshotSize.java
41153 views
/*1* Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/* @test24* @bug 431986625* @summary Verify that ReliableLog.snapshotSize() returns correct snapshot26* file size even if LogHandler doesn't flush.27*28* @modules java.rmi/sun.rmi.log29* @run main/othervm SnapshotSize30*/3132import java.io.ByteArrayOutputStream;33import java.io.OutputStream;34import java.io.ObjectOutputStream;35import java.io.IOException;36import sun.rmi.log.LogHandler;37import sun.rmi.log.ReliableLog;3839public class SnapshotSize extends LogHandler {4041int lastSnapshotSize = -1;4243public static void main(String[] args) throws Exception {44SnapshotSize handler = new SnapshotSize();45ReliableLog log = new ReliableLog(".", handler);46if (log.snapshotSize() != handler.lastSnapshotSize) {47throw new Error();48}4950String[] snapshots = { "some", "sample", "objects", "to", "snapshot" };51for (int i = 0; i < snapshots.length; i++) {52log.snapshot(snapshots[i]);53if (log.snapshotSize() != handler.lastSnapshotSize) {54throw new Error();55}56}57}5859public Object initialSnapshot() {60return "initial snapshot";61}6263public void snapshot(OutputStream out, Object value) throws IOException {64ByteArrayOutputStream bout = new ByteArrayOutputStream();65ObjectOutputStream oout = new ObjectOutputStream(bout);66oout.writeObject(value);67oout.close();6869byte[] buf = bout.toByteArray();70out.write(buf); // leave unflushed71lastSnapshotSize = buf.length;72}7374public Object applyUpdate(Object update, Object state) {75return state;76}77}787980