0N/A/*
2362N/A * Copyright (c) 1997, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/* @test
5551N/A * @bug 4094889
5551N/A * @summary rmid can have a corrupted log
5551N/A *
5551N/A * @run main LogAlignmentTest
0N/A */
0N/A
0N/A/* Fault: ReliableLog used RandomAccessFile.skipBytes() to seek past the end
0N/A * of a file. Unfortunately, skipBytes() doesn't do that, so the file was
0N/A * being misaligned.
0N/A *
0N/A * Reproduced by writing an odd number of bytes into an update, and then
0N/A * reloading.
0N/A */
0N/A
0N/Aimport java.io.File;
0N/Aimport java.io.PrintStream;
0N/Aimport java.io.Serializable;
0N/Aimport sun.rmi.log.LogHandler;
0N/Aimport sun.rmi.log.ReliableLog;
0N/A
0N/A//import javasoft.sqe.harness.Status;
0N/A//import javasoft.sqe.harness.Test;
0N/A
0N/Apublic class LogAlignmentTest
0N/A extends LogHandler
0N/A implements Serializable //, Test
0N/A{
0N/A static public void main (String[] argv)
0N/A {
0N/A LogAlignmentTest test = new LogAlignmentTest();
0N/A //Status status = test.run (argv, System.err, System.out);
0N/A //status.exit();
0N/A test.run (argv, System.err, System.out);
0N/A }
0N/A
0N/A //public Status run (String argv[], PrintStream log, PrintStream out)
0N/A public void run (String argv[], PrintStream log, PrintStream out)
0N/A {
0N/A try {
0N/A regtest(130, "./logalign_tmp", log, out);
0N/A regtest(131, "./logalign_tmp", log, out);
0N/A } catch (Exception e) {
0N/A e.printStackTrace (log);
0N/A //return (Status.failed
0N/A throw (new RuntimeException
0N/A ("Exception in regression test for bugid 4094889"));
0N/A }
0N/A //return (Status.passed ("OKAY"));
0N/A }
0N/A
0N/A static private void regtest(int updatesz, String dir, PrintStream lg, PrintStream out)
0N/A throws Exception
0N/A {
0N/A try {
0N/A LogAlignmentTest handler = new LogAlignmentTest();
0N/A ReliableLog log = new ReliableLog (dir, handler, false);
0N/A
0N/A // Write a preamble update
0N/A String c = "[";
0N/A handler.basicUpdate (c);
0N/A log.update (c, true);
0N/A
0N/A // Generate the requested size update (single chars)
0N/A char[] up = new char[updatesz];
0N/A int i;
0N/A for (i = 0; i < updatesz; i++) {
0N/A up[i] = (char)(65 + (i % 26));
0N/A }
0N/A c = new String (up);
0N/A handler.basicUpdate (c);
0N/A log.update (c, true);
0N/A
0N/A // Write it again, so we can misalign
0N/A handler.basicUpdate (c);
0N/A log.update (c, true);
0N/A
0N/A // Write the suffix
0N/A c = "]";
0N/A handler.basicUpdate (c);
0N/A log.update (c, true);
0N/A
0N/A // Read it back using a new context.
0N/A LogAlignmentTest handler2 = new LogAlignmentTest();
0N/A ReliableLog carbon = new ReliableLog (dir, handler2, false);
0N/A Object thingy = carbon.recover();
0N/A
0N/A // The report bit
0N/A String orig = handler.contents;
0N/A String news = ((LogAlignmentTest)thingy).contents;
0N/A lg.println ("Original as saved: " + orig);
0N/A lg.println ("As restored : " + news);
0N/A if (orig.compareTo (news) != 0) {
0N/A throw new RuntimeException ("Restored string was different from saved string");
0N/A } else {
0N/A lg.println ("Matched OK. Test element passed.");
0N/A }
0N/A } finally {
0N/A // Trash the log directory, so a new snap will be taken in the next test
0N/A try {
0N/A File vs = new File (dir, "Version_Number");
0N/A vs.delete();
0N/A } catch (Exception e) {
0N/A }
0N/A try {
0N/A File vs = new File (dir, "New_Version_Number");
0N/A vs.delete();
0N/A } catch (Exception e) {
0N/A }
0N/A }
0N/A }
0N/A
0N/A private String contents;
0N/A
0N/A public LogAlignmentTest()
0N/A {
0N/A super();
0N/A this.contents = "?";
0N/A }
0N/A
0N/A // implements LogHandler.initialSnapshot()
0N/A public Object initialSnapshot()
0N/A throws Exception
0N/A {
0N/A this.contents = "";
0N/A return (this);
0N/A }
0N/A
0N/A // implements LogHandler.applyUpdate()
0N/A public Object applyUpdate (Object update, Object state)
0N/A throws Exception
0N/A {
0N/A // basicUpdate appends the string
0N/A ((LogAlignmentTest)state).basicUpdate ((String)update);
0N/A return (state);
0N/A }
0N/A
0N/A // an "update" is a short string to append to this.contents (must ignore state)
0N/A public void basicUpdate (String extra)
0N/A {
0N/A this.contents = this.contents + extra;
0N/A }
0N/A}