jdk/test/sun/rmi/log/ReliableLog/LogAlignmentTest.java
author shade
Thu, 02 Oct 2014 17:13:31 +0400
changeset 27003 19617f4c9dd0
parent 23010 6dadb192ad81
child 30820 0d4717a011d3
permissions -rw-r--r--
8059595: Verifier::verify is wasting time before is_eligible_for_verification check Summary: Do the check earlier. Reviewed-by: hseigel, kamg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 22969
diff changeset
     2
 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/* @test
14778
5947768d173d 8004748: clean up @build tags in RMI tests
smarks
parents: 5506
diff changeset
    25
 * @bug 4094889
5947768d173d 8004748: clean up @build tags in RMI tests
smarks
parents: 5506
diff changeset
    26
 * @summary rmid can have a corrupted log
5947768d173d 8004748: clean up @build tags in RMI tests
smarks
parents: 5506
diff changeset
    27
 *
22969
d5c38e7ba6d0 8034000: lack of /othervm option can cause some RMI tests to fail
smarks
parents: 14778
diff changeset
    28
 * @run main/othervm LogAlignmentTest
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/* Fault: ReliableLog used RandomAccessFile.skipBytes() to seek past the end
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * of a file.  Unfortunately, skipBytes() doesn't do that, so the file was
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * being misaligned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * Reproduced by writing an odd number of bytes into an update, and then
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * reloading.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.io.PrintStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import sun.rmi.log.LogHandler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import sun.rmi.log.ReliableLog;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
//import javasoft.sqe.harness.Status;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
//import javasoft.sqe.harness.Test;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
public class LogAlignmentTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    extends LogHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    implements Serializable //, Test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    static public void main (String[] argv)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        LogAlignmentTest test = new LogAlignmentTest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        //Status status = test.run (argv, System.err, System.out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        //status.exit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        test.run (argv, System.err, System.out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    //public Status run (String argv[], PrintStream log, PrintStream out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    public void run (String argv[], PrintStream log, PrintStream out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
            regtest(130, "./logalign_tmp", log, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            regtest(131, "./logalign_tmp", log, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            e.printStackTrace (log);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            //return (Status.failed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            throw (new RuntimeException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                    ("Exception in regression test for bugid 4094889"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        //return (Status.passed ("OKAY"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    static private void regtest(int updatesz, String dir, PrintStream lg, PrintStream out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        throws Exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            LogAlignmentTest handler = new LogAlignmentTest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            ReliableLog log = new ReliableLog (dir, handler, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            // Write a preamble update
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            String c = "[";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            handler.basicUpdate (c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            log.update (c, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            // Generate the requested size update (single chars)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            char[] up = new char[updatesz];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            for (i = 0; i < updatesz; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                up[i] = (char)(65 + (i % 26));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            c = new String (up);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            handler.basicUpdate (c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            log.update (c, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            // Write it again, so we can misalign
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            handler.basicUpdate (c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            log.update (c, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            // Write the suffix
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            c = "]";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            handler.basicUpdate (c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            log.update (c, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            // Read it back using a new context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            LogAlignmentTest handler2 = new LogAlignmentTest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            ReliableLog carbon = new ReliableLog (dir, handler2, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            Object thingy = carbon.recover();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            // The report bit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            String orig = handler.contents;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            String news = ((LogAlignmentTest)thingy).contents;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            lg.println ("Original as saved: " + orig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            lg.println ("As restored      : " + news);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            if (orig.compareTo (news) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                throw new RuntimeException ("Restored string was different from saved string");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                lg.println ("Matched OK.  Test element passed.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            // Trash the log directory, so a new snap will be taken in the next test
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                File vs = new File (dir, "Version_Number");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                vs.delete();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                File vs = new File (dir, "New_Version_Number");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                vs.delete();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    private String contents;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    public LogAlignmentTest()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        this.contents = "?";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    // implements LogHandler.initialSnapshot()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    public Object initialSnapshot()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        throws Exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        this.contents = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        return (this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    // implements LogHandler.applyUpdate()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    public Object applyUpdate (Object update, Object state)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        throws Exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        // basicUpdate appends the string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        ((LogAlignmentTest)state).basicUpdate ((String)update);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        return (state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    // an "update" is a short string to append to this.contents (must ignore state)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    public void basicUpdate (String extra)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        this.contents = this.contents + extra;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
}