1# See the file LICENSE for redistribution information.
2#
3# Copyright (c) 1996,2008 Oracle.  All rights reserved.
4#
5# $Id: test058.tcl,v 12.6 2008/01/08 20:58:53 bostic Exp $
6#
7# TEST	test058
8# TEST	Verify that deleting and reading duplicates results in correct ordering.
9proc test058 { method args } {
10	source ./include.tcl
11
12	#
13	# If we are using an env, then skip this test.  It needs its own.
14	set eindex [lsearch -exact $args "-env"]
15	if { $eindex != -1 } {
16		incr eindex
17		set env [lindex $args $eindex]
18		puts "Test058 skipping for env $env"
19		return
20	}
21	set args [convert_args $method $args]
22	set encargs ""
23	set args [split_encargs $args encargs]
24	set omethod [convert_method $method]
25
26	if { [is_record_based $method] == 1 || [is_rbtree $method] == 1 } {
27		puts "Test058: skipping for method $method"
28		return
29	}
30	puts "Test058: $method delete dups after inserting after duped key."
31
32	# environment
33	env_cleanup $testdir
34	set eflags "-create -txn $encargs -home $testdir"
35	set env [eval {berkdb_env} $eflags]
36	error_check_good env [is_valid_env $env] TRUE
37
38	# db open
39	set flags "-auto_commit -create -mode 0644 -dup -env $env $args"
40	set db [eval {berkdb_open} $flags $omethod "test058.db"]
41	error_check_good dbopen [is_valid_db $db] TRUE
42
43	set tn ""
44	set tid ""
45	set tn [$env txn]
46	set tflags "-txn $tn"
47
48	puts "\tTest058.a: Adding 10 duplicates"
49	# Add a bunch of dups
50	for { set i 0 } { $i < 10 } {incr i} {
51		set ret \
52		    [eval {$db put} $tflags {doghouse $i"DUPLICATE_DATA_VALUE"}]
53		error_check_good db_put $ret 0
54	}
55
56	puts "\tTest058.b: Adding key after duplicates"
57	# Now add one more key/data AFTER the dup set.
58	set ret [eval {$db put} $tflags {zebrahouse NOT_A_DUP}]
59	error_check_good db_put $ret 0
60
61	error_check_good txn_commit [$tn commit] 0
62
63	set tn [$env txn]
64	error_check_good txnbegin [is_substr $tn $env] 1
65	set tflags "-txn $tn"
66
67	# Now delete everything
68	puts "\tTest058.c: Deleting duplicated key"
69	set ret [eval {$db del} $tflags {doghouse}]
70	error_check_good del $ret 0
71
72	# Now reput everything
73	set pad \
74	    abcdefghijklmnopqrtsuvabcdefghijklmnopqrtsuvabcdefghijklmnopqrtsuvabcdefghijklmnopqrtsuvabcdefghijklmnopqrtsuvabcdefghijklmnopqrtsuvabcdefghijklmnopqrtsuvabcdefghijklmnopqrtsuvabcdefghijklmnopqrtsuvabcdefghijklmnopqrtsuv
75
76	puts "\tTest058.d: Reputting duplicates with big data vals"
77	for { set i 0 } { $i < 10 } {incr i} {
78		set ret [eval {$db put} \
79		    $tflags {doghouse $i"DUPLICATE_DATA_VALUE"$pad}]
80		error_check_good db_put $ret 0
81	}
82	error_check_good txn_commit [$tn commit] 0
83
84	# Check duplicates for order
85	set dbc [$db cursor]
86	error_check_good db_cursor [is_substr $dbc $db] 1
87
88	puts "\tTest058.e: Verifying that duplicates are in order."
89	set i 0
90	for { set ret [$dbc get -set doghouse] } \
91	    {$i < 10 && [llength $ret] != 0} \
92	    { set ret [$dbc get -nextdup] } {
93		set data [lindex [lindex $ret 0] 1]
94		error_check_good \
95		    duplicate_value $data $i"DUPLICATE_DATA_VALUE"$pad
96		incr i
97	}
98
99	error_check_good dbc_close [$dbc close] 0
100	error_check_good db_close [$db close] 0
101	reset_env $env
102}
103