* FYI: New Hashtable test
@ 2006-01-12 0:10 Roman Kennke
0 siblings, 0 replies; only message in thread
From: Roman Kennke @ 2006-01-12 0:10 UTC (permalink / raw)
To: mauve-patches
[-- Attachment #1: Type: text/plain, Size: 277 bytes --]
This test accompanies my latest Hashtable fix. It checks if modifying a
Hashtable while enumerating over it throws an exception or not.
2006-01-11 Roman Kennke <kennke@aicas.com>
* gnu/testlet/java/util/Hashtable/EnumerateAndModify.java: New
test.
/Roman
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: EnumerateAndModify.java --]
[-- Type: text/x-java; name="EnumerateAndModify.java", Size: 4642 bytes --]
/* EnumerateAndModify.java -- A test for Hashtable
Copyright (C) 2006 Fridjof Siebert
This file is part of Mauve.
Mauve is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
Mauve is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with Mauve; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
*/
// Tags: JDK1.0
package gnu.testlet.java.util.Hashtable;
import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;
import java.util.Hashtable;
import java.util.Enumeration;
/**
* EnumerateAndModify tests that enumerating a Hashtable that is
* concurrently modified will not throw an exception.
*
* @author Fridtjof Siebert (siebert@aicas.com)
*/
public class EnumerateAndModify implements Testlet
{
/**
* test is the main test routine testing enumaration of keys and
* elements of a concurrently modified hashtable.
*
* @param harness the current test harness.
*/
public void test(TestHarness harness)
{
Hashtable allKeys = new Hashtable();
allKeys.put("C","c");
allKeys.put("D","d");
allKeys.put("A","a");
allKeys.put("B","b");
allKeys.put("E","e");
allKeys.put("C1","c");
allKeys.put("D1","d");
allKeys.put("A1","a");
allKeys.put("B1","b");
allKeys.put("E1","e");
Hashtable allElements = new Hashtable();
allElements.put("c","c");
allElements.put("d","d");
allElements.put("a","a");
allElements.put("b","b");
allElements.put("e","e");
allElements.put("c1","c1");
allElements.put("d1","d1");
allElements.put("a1","a1");
allElements.put("b1","b1");
allElements.put("e1","e1");
Hashtable ht = new Hashtable();
ht.put("A","a");
ht.put("B","b");
ht.put("C","c");
ht.put("D","d");
ht.put("E","e");
Throwable thrown;
boolean returnedOnlyKeysThatWerePut = true;
try
{
// We walk through the keys while we modify the hashtable. This
// is not legal, and the result of the enumaration is undefined,
// but we should not get any exception when enumerating and we
// should not get null or any key that was never added.
for (Enumeration e = ht.keys(); e.hasMoreElements(); )
{
String str = (String) e.nextElement();
if (str != null && !allKeys.containsKey(str))
{
returnedOnlyKeysThatWerePut = false;
}
ht.put("C","c");
ht.put("D","d");
ht.put("A","a");
ht.put("B","b");
ht.put("E","e");
ht.put("C1","c");
ht.put("D1","d");
ht.put("A1","a");
ht.put("B1","b");
ht.put("E1","e");
}
thrown = null;
}
catch (Throwable t)
{
t.printStackTrace();
thrown = t;
}
harness.check(thrown == null);
harness.check(returnedOnlyKeysThatWerePut);
ht = new Hashtable();
ht.put("A","a");
ht.put("B","b");
ht.put("C","c");
ht.put("D","d");
ht.put("E","e");
boolean returnedOnlyElementsThatWerePut = true;
try
{
// We walk through the keys while we modify the hashtable. This
// is not legal, and the result of the enumaration is undefined,
// but we should not get any exception when enumerating and we
// should not get null or any key that was never added.
for (Enumeration e = ht.elements(); e.hasMoreElements(); )
{
String str = (String) e.nextElement();
if (str != null && !allElements.containsKey(str))
{
returnedOnlyElementsThatWerePut = false;
}
ht.put("C","c");
ht.put("D","d");
ht.put("A","a");
ht.put("B","b");
ht.put("E","e");
ht.put("C1","c1");
ht.put("D1","d1");
ht.put("A1","a1");
ht.put("B1","b1");
ht.put("E1","e1");
}
thrown = null;
}
catch (Throwable t)
{
thrown = t;
}
harness.check(thrown == null);
harness.check(returnedOnlyElementsThatWerePut);
}
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2006-01-12 0:10 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-01-12 0:10 FYI: New Hashtable test Roman Kennke
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).