8255031: Update java/util/prefs/AddNodeChangeListener.java to report more failure info
Reviewed-by: bpb
This commit is contained in:
parent
0aa3c92577
commit
8afdcaee1c
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -23,6 +23,7 @@
|
|||||||
|
|
||||||
/* @test
|
/* @test
|
||||||
* @bug 7160252 7197662
|
* @bug 7160252 7197662
|
||||||
|
* @key intermittent
|
||||||
* @summary Checks if events are delivered to a listener
|
* @summary Checks if events are delivered to a listener
|
||||||
* when a child node is added or removed
|
* when a child node is added or removed
|
||||||
* @run main/othervm -Djava.util.prefs.userRoot=. AddNodeChangeListener
|
* @run main/othervm -Djava.util.prefs.userRoot=. AddNodeChangeListener
|
||||||
@ -30,15 +31,15 @@
|
|||||||
|
|
||||||
import java.util.prefs.*;
|
import java.util.prefs.*;
|
||||||
|
|
||||||
public class AddNodeChangeListener {
|
public class AddNodeChangeListener {
|
||||||
|
|
||||||
private static boolean failed = false;
|
private static final int SLEEP_ITRS = 10;
|
||||||
private static Preferences userRoot, N2;
|
private static boolean failed = false;
|
||||||
private static NodeChangeListenerAdd ncla;
|
private static Preferences userRoot, N2;
|
||||||
|
private static NodeChangeListenerAdd ncla;
|
||||||
|
|
||||||
public static void main(String[] args)
|
public static void main(String[] args)
|
||||||
throws BackingStoreException, InterruptedException
|
throws BackingStoreException, InterruptedException {
|
||||||
{
|
|
||||||
userRoot = Preferences.userRoot();
|
userRoot = Preferences.userRoot();
|
||||||
ncla = new NodeChangeListenerAdd();
|
ncla = new NodeChangeListenerAdd();
|
||||||
userRoot.addNodeChangeListener(ncla);
|
userRoot.addNodeChangeListener(ncla);
|
||||||
@ -49,28 +50,61 @@ import java.util.prefs.*;
|
|||||||
//Should initate a child removed event
|
//Should initate a child removed event
|
||||||
removeNode();
|
removeNode();
|
||||||
|
|
||||||
if (failed)
|
if (failed) {
|
||||||
throw new RuntimeException("Failed");
|
throw new RuntimeException("Failed");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void addNode()
|
private static void addNode()
|
||||||
throws BackingStoreException, InterruptedException
|
throws BackingStoreException, InterruptedException {
|
||||||
{
|
|
||||||
N2 = userRoot.node("N2");
|
N2 = userRoot.node("N2");
|
||||||
userRoot.flush();
|
userRoot.flush();
|
||||||
Thread.sleep(3000);
|
int passItr = -1;
|
||||||
if (ncla.getAddNumber() != 1)
|
|
||||||
failed = true;
|
for (int i = 0; i < SLEEP_ITRS; i++) {
|
||||||
|
System.out.print("addNode sleep iteration " + i + "...");
|
||||||
|
Thread.sleep(3000);
|
||||||
|
System.out.println("done.");
|
||||||
|
if (ncla.getAddNumber() == 1) {
|
||||||
|
passItr = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
checkPassItr(passItr, "addNode()");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void removeNode()
|
private static void removeNode()
|
||||||
throws BackingStoreException, InterruptedException
|
throws BackingStoreException, InterruptedException {
|
||||||
{
|
|
||||||
N2.removeNode();
|
N2.removeNode();
|
||||||
userRoot.flush();
|
userRoot.flush();
|
||||||
Thread.sleep(3000);
|
int passItr = -1;
|
||||||
if (ncla.getAddNumber() != 0)
|
|
||||||
|
for (int i = 0; i < SLEEP_ITRS; i++) {
|
||||||
|
System.out.print("removeNode sleep iteration " + i + "...");
|
||||||
|
Thread.sleep(3000);
|
||||||
|
System.out.println("done.");
|
||||||
|
if (ncla.getAddNumber() == 0) {
|
||||||
|
passItr = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
checkPassItr(passItr, "removeNode()");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If the listener wasn't notified on iteration 0, throw a RuntimeException
|
||||||
|
* with some contextual information
|
||||||
|
*/
|
||||||
|
private static void checkPassItr(int itr, String methodName) {
|
||||||
|
if (itr == 0) {
|
||||||
|
System.out.println(methodName + " test passed");
|
||||||
|
} else {
|
||||||
failed = true;
|
failed = true;
|
||||||
|
if (itr == -1) {
|
||||||
|
throw new RuntimeException("Failed in " + methodName + " - change listener never notified");
|
||||||
|
} else {
|
||||||
|
throw new RuntimeException("Failed in " + methodName + " - listener notified on iteration " + itr);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class NodeChangeListenerAdd implements NodeChangeListener {
|
private static class NodeChangeListenerAdd implements NodeChangeListener {
|
||||||
@ -90,4 +124,4 @@ import java.util.prefs.*;
|
|||||||
return totalNode;
|
return totalNode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user