summaryrefslogtreecommitdiff
path: root/test/java/junit
diff options
context:
space:
mode:
Diffstat (limited to 'test/java/junit')
-rw-r--r--test/java/junit/makenewtest.sh2
-rw-r--r--test/java/junit/src/com/sleepycat/db/test/AppendRecnoTest.java2
-rw-r--r--test/java/junit/src/com/sleepycat/db/test/AssociateTest.java2
-rw-r--r--test/java/junit/src/com/sleepycat/db/test/BackupTest.java2
-rw-r--r--test/java/junit/src/com/sleepycat/db/test/CallbackTest.java2
-rw-r--r--test/java/junit/src/com/sleepycat/db/test/ClosedDbTest.java2
-rw-r--r--test/java/junit/src/com/sleepycat/db/test/DatabaseTest.java629
-rw-r--r--test/java/junit/src/com/sleepycat/db/test/EncryptTest.java2
-rw-r--r--test/java/junit/src/com/sleepycat/db/test/EnvRegionSizeTest.java2
-rw-r--r--test/java/junit/src/com/sleepycat/db/test/HashCompareTest.java2
-rw-r--r--test/java/junit/src/com/sleepycat/db/test/LogCursorTest.java2
-rw-r--r--test/java/junit/src/com/sleepycat/db/test/MultipleCursorTest.java2
-rw-r--r--test/java/junit/src/com/sleepycat/db/test/PartialGetTest.java2
-rw-r--r--test/java/junit/src/com/sleepycat/db/test/PriorityTest.java2
-rw-r--r--test/java/junit/src/com/sleepycat/db/test/RepmgrConfigTest.java2
-rw-r--r--test/java/junit/src/com/sleepycat/db/test/RepmgrElectionTest.java2
-rw-r--r--test/java/junit/src/com/sleepycat/db/test/RepmgrSiteTest.java136
-rw-r--r--test/java/junit/src/com/sleepycat/db/test/RepmgrStartupTest.java17
-rw-r--r--test/java/junit/src/com/sleepycat/db/test/TestUtils.java11
-rw-r--r--test/java/junit/src/com/sleepycat/db/test/VerboseConfigTest.java2
20 files changed, 761 insertions, 64 deletions
diff --git a/test/java/junit/makenewtest.sh b/test/java/junit/makenewtest.sh
index 0ff04e68..60e36004 100644
--- a/test/java/junit/makenewtest.sh
+++ b/test/java/junit/makenewtest.sh
@@ -42,7 +42,7 @@ namelower=`echo $1 | tr -t [:upper:] [:lower:]`
echo "/*-" >> $outname
echo " * See the file LICENSE for redistribution information." >> $outname
echo " * " >> $outname
-echo " * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved." >> $outname
+echo " * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved." >> $outname
echo " *" >> $outname
echo " */" >> $outname
echo "" >> $outname
diff --git a/test/java/junit/src/com/sleepycat/db/test/AppendRecnoTest.java b/test/java/junit/src/com/sleepycat/db/test/AppendRecnoTest.java
index f3c8b307..f70ca823 100644
--- a/test/java/junit/src/com/sleepycat/db/test/AppendRecnoTest.java
+++ b/test/java/junit/src/com/sleepycat/db/test/AppendRecnoTest.java
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved.
*
*/
diff --git a/test/java/junit/src/com/sleepycat/db/test/AssociateTest.java b/test/java/junit/src/com/sleepycat/db/test/AssociateTest.java
index 3cf8b187..2f9c0540 100644
--- a/test/java/junit/src/com/sleepycat/db/test/AssociateTest.java
+++ b/test/java/junit/src/com/sleepycat/db/test/AssociateTest.java
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved.
*
*/
diff --git a/test/java/junit/src/com/sleepycat/db/test/BackupTest.java b/test/java/junit/src/com/sleepycat/db/test/BackupTest.java
index 6b41336d..f5303870 100644
--- a/test/java/junit/src/com/sleepycat/db/test/BackupTest.java
+++ b/test/java/junit/src/com/sleepycat/db/test/BackupTest.java
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved.
*
*/
diff --git a/test/java/junit/src/com/sleepycat/db/test/CallbackTest.java b/test/java/junit/src/com/sleepycat/db/test/CallbackTest.java
index 2b65f79b..6668dd59 100644
--- a/test/java/junit/src/com/sleepycat/db/test/CallbackTest.java
+++ b/test/java/junit/src/com/sleepycat/db/test/CallbackTest.java
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved.
*
*/
diff --git a/test/java/junit/src/com/sleepycat/db/test/ClosedDbTest.java b/test/java/junit/src/com/sleepycat/db/test/ClosedDbTest.java
index 4d0e72b3..f2848825 100644
--- a/test/java/junit/src/com/sleepycat/db/test/ClosedDbTest.java
+++ b/test/java/junit/src/com/sleepycat/db/test/ClosedDbTest.java
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved.
*
*/
diff --git a/test/java/junit/src/com/sleepycat/db/test/DatabaseTest.java b/test/java/junit/src/com/sleepycat/db/test/DatabaseTest.java
index c3a03885..a5886fa8 100644
--- a/test/java/junit/src/com/sleepycat/db/test/DatabaseTest.java
+++ b/test/java/junit/src/com/sleepycat/db/test/DatabaseTest.java
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved.
*
*/
@@ -18,27 +18,37 @@ import org.junit.After;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
+import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import com.sleepycat.db.BtreeStats;
import com.sleepycat.db.Cursor;
import com.sleepycat.db.CursorConfig;
import com.sleepycat.db.Database;
import com.sleepycat.db.DatabaseConfig;
import com.sleepycat.db.DatabaseEntry;
import com.sleepycat.db.DatabaseException;
+import com.sleepycat.db.DatabaseStream;
+import com.sleepycat.db.DatabaseStreamConfig;
import com.sleepycat.db.DatabaseType;
import com.sleepycat.db.Environment;
import com.sleepycat.db.EnvironmentConfig;
+import com.sleepycat.db.HashStats;
import com.sleepycat.db.HeapStats;
import com.sleepycat.db.LockMode;
+import com.sleepycat.db.MultipleDataEntry;
import com.sleepycat.db.OperationStatus;
+import com.sleepycat.db.PartitionHandler;
import com.sleepycat.db.Transaction;
import java.io.File;
import java.io.IOException;
import java.io.FileNotFoundException;
+import java.lang.reflect.Array;
import com.sleepycat.db.test.TestUtils;
public class DatabaseTest {
@@ -68,37 +78,38 @@ public class DatabaseTest {
}
/*
- * Test creating a new database.
+ * Test creating a new database, and then
+ * opening and adding records to an existing database.
*/
@Test public void test1()
throws DatabaseException, FileNotFoundException
{
+ TestUtils.removeall(true, true, TestUtils.BASETEST_DBDIR,
+ TestUtils.getDBFileName(DATABASETEST_DBNAME));
+ itemcount = 0;
+
+ // Create a new database.
TestOptions options = new TestOptions();
options.db_config.setErrorPrefix("DatabaseTest::test1 ");
rundb(itemcount++, options);
- }
-
- /*
- * Test opening and adding to an existing database.
- */
- @Test public void test2()
- throws DatabaseException, FileNotFoundException
- {
- TestOptions options = new TestOptions();
- options.db_config.setErrorPrefix("DatabaseTest::test2 ");
+ // Open and add records to the existing database.
rundb(itemcount++, options);
}
/*
- * Test modifying the error prefix multiple times ?
+ * Test modifying the error prefix multiple times.
*/
- @Test public void test3()
+ @Test public void test2()
throws DatabaseException, FileNotFoundException
{
+ TestUtils.removeall(true, true, TestUtils.BASETEST_DBDIR,
+ TestUtils.getDBFileName(DATABASETEST_DBNAME));
+ itemcount = 0;
+
TestOptions options = new TestOptions();
- options.db_config.setErrorPrefix("DatabaseTest::test3 ");
+ options.db_config.setErrorPrefix("DatabaseTest::test2 ");
for (int i=0; i<100; i++)
options.db_config.setErrorPrefix("str" + i);
@@ -109,11 +120,15 @@ public class DatabaseTest {
/*
* Test opening a database with an env.
*/
- @Test public void test4()
+ @Test public void test3()
throws DatabaseException, FileNotFoundException
{
+ TestUtils.removeall(true, true, TestUtils.BASETEST_DBDIR,
+ TestUtils.getDBFileName(DATABASETEST_DBNAME));
+ itemcount = 0;
+
TestOptions options = new TestOptions();
- options.db_config.setErrorPrefix("DatabaseTest::test4 ");
+ options.db_config.setErrorPrefix("DatabaseTest::test3 ");
EnvironmentConfig envc = new EnvironmentConfig();
envc.setAllowCreate(true);
@@ -127,11 +142,15 @@ public class DatabaseTest {
/*
* Test opening multiple databases using the same env.
*/
- @Test public void test5()
+ @Test public void test4()
throws DatabaseException, FileNotFoundException
{
+ TestUtils.removeall(true, true, TestUtils.BASETEST_DBDIR,
+ TestUtils.getDBFileName(DATABASETEST_DBNAME));
+ itemcount = 0;
+
TestOptions options = new TestOptions();
- options.db_config.setErrorPrefix("DatabaseTest::test5 ");
+ options.db_config.setErrorPrefix("DatabaseTest::test4 ");
EnvironmentConfig envc = new EnvironmentConfig();
envc.setAllowCreate(true);
@@ -146,15 +165,22 @@ public class DatabaseTest {
}
/*
- * Test just opening and closing a DB and an Env without doing any operations.
+ * Test just opening and closing a DB and an Env without
+ * doing any operations.
*/
- @Test public void test6()
+ @Test public void test5()
throws DatabaseException, FileNotFoundException
{
+ TestUtils.removeall(true, true, TestUtils.BASETEST_DBDIR,
+ TestUtils.getDBFileName(DATABASETEST_DBNAME));
+
TestOptions options = new TestOptions();
- options.db_config.setErrorPrefix("DatabaseTest::test6 ");
+ options.db_config.setErrorPrefix("DatabaseTest::test5 ");
+ options.db_config.setAllowCreate(true);
- Database db = new Database(TestUtils.getDBFileName(DATABASETEST_DBNAME), null, options.db_config);
+ Database db =
+ new Database(TestUtils.getDBFileName(DATABASETEST_DBNAME),
+ null, options.db_config);
EnvironmentConfig envc = new EnvironmentConfig();
envc.setAllowCreate(true);
@@ -169,14 +195,14 @@ public class DatabaseTest {
}
/*
- * test7 leaves a db and dbenv open; it should be detected.
+ * test6 leaves a db and dbenv open; it should be detected.
*/
/* Not sure if relevant with current API.
- @Test public void test7()
+ @Test public void test6()
throws DatabaseException, FileNotFoundException
{
TestOptions options = new TestOptions();
- options.db_config.setErrorPrefix("DatabaseTest::test7 ");
+ options.db_config.setErrorPrefix("DatabaseTest::test6 ");
Database db = new Database(TestUtils.getDBFileName(DATABASETEST_DBNAME), null, options.db_config);
@@ -192,25 +218,25 @@ public class DatabaseTest {
/*
* Test leaving database and cursors open won't harm.
*/
- @Test public void test10()
+ @Test public void test8()
throws DatabaseException, FileNotFoundException
{
System.out.println("\nTest 10 transactional.");
- test10_int(true);
+ test8_int(true);
System.out.println("\nTest 10 non-transactional.");
- test10_int(false);
+ test8_int(false);
}
- void test10_int(boolean havetxn)
+ void test8_int(boolean havetxn)
throws DatabaseException, FileNotFoundException
{
String name;
Transaction txn = null;
-
itemcount = 0;
+ TestUtils.removeall(true, true, TestUtils.BASETEST_DBDIR, TestUtils.getDBFileName(DATABASETEST_DBNAME));
TestOptions options = new TestOptions();
options.save_db = true;
- options.db_config.setErrorPrefix("DatabaseTest::test10 ");
+ options.db_config.setErrorPrefix("DatabaseTest::test8 ");
EnvironmentConfig envc = new EnvironmentConfig();
envc.setAllowCreate(true);
@@ -273,14 +299,16 @@ public class DatabaseTest {
/*
* Test creating a new database.
*/
- @Test public void test8()
+ @Test public void test7()
throws DatabaseException, FileNotFoundException
{
- TestUtils.removeall(true, false, TestUtils.BASETEST_DBDIR, TestUtils.getDBFileName(DATABASETEST_DBNAME));
- itemcount = 0;
+ TestUtils.removeall(true, true, TestUtils.BASETEST_DBDIR,
+ TestUtils.getDBFileName(DATABASETEST_DBNAME));
+ itemcount = 0;
+
TestOptions options = new TestOptions();
options.save_db = true;
- options.db_config.setErrorPrefix("DatabaseTest::test8 ");
+ options.db_config.setErrorPrefix("DatabaseTest::test7 ");
EnvironmentConfig envc = new EnvironmentConfig();
envc.setAllowCreate(true);
@@ -308,20 +336,21 @@ public class DatabaseTest {
options.database.close();
options.database = null;
+ options.db_env.close();
}
/*
* Test setting database handle exclusive lock.
*/
- @Test public void test11()
+ @Test public void test9()
throws DatabaseException, FileNotFoundException
{
TestUtils.removeall(true, true, TestUtils.BASETEST_DBDIR, TestUtils.getDBFileName(DATABASETEST_DBNAME));
itemcount = 0;
TestOptions options = new TestOptions();
options.save_db = true;
- options.db_config.setErrorPrefix("DatabaseTest::test11 ");
+ options.db_config.setErrorPrefix("DatabaseTest::test9 ");
EnvironmentConfig envc = new EnvironmentConfig();
envc.setAllowCreate(true);
@@ -365,13 +394,13 @@ public class DatabaseTest {
/*
* Test setting metadata directory
*/
- @Test public void test12()
+ @Test public void test10()
throws DatabaseException, FileNotFoundException
{
TestUtils.removeall(true, true, TestUtils.BASETEST_DBDIR, TestUtils.getDBFileName(DATABASETEST_DBNAME));
itemcount = 0;
TestOptions options = new TestOptions();
- options.db_config.setErrorPrefix("DatabaseTest::test12 ");
+ options.db_config.setErrorPrefix("DatabaseTest::test10 ");
EnvironmentConfig envc = new EnvironmentConfig();
envc.setAllowCreate(true);
@@ -393,12 +422,12 @@ public class DatabaseTest {
/*
* Test setting heap region size
*/
- @Test public void test13()
+ @Test public void test11()
throws DatabaseException, FileNotFoundException
{
TestUtils.removeall(true, true, TestUtils.BASETEST_DBDIR, TestUtils.getDBFileName(DATABASETEST_DBNAME));
TestOptions options = new TestOptions();
- options.db_config.setErrorPrefix("DatabaseTest::test13 ");
+ options.db_config.setErrorPrefix("DatabaseTest::test11 ");
options.db_config.setAllowCreate(true);
options.db_config.setType(DatabaseType.HEAP);
options.db_config.setHeapRegionSize(4);
@@ -412,6 +441,170 @@ public class DatabaseTest {
db.close();
}
+ /*
+ * Test creating partition database by keys
+ */
+ @Test public void test12()
+ throws DatabaseException, Exception, FileNotFoundException
+ {
+ // Test the success case
+ String errpfx = "DatabaseTest::test12 ";
+
+ // Create the partition key
+ int parts = 3;
+ MultipleDataEntry keyRanges = new MultipleDataEntry();
+ keyRanges.setData(new byte[1024]);
+ keyRanges.setUserBuffer(1024, true);
+
+ DatabaseEntry kdbt1 = new DatabaseEntry();
+ DatabaseEntry kdbt2 = new DatabaseEntry();
+ kdbt1.setData("d".getBytes());
+ kdbt2.setData("g".getBytes());
+
+ keyRanges.append(kdbt1);
+ keyRanges.append(kdbt2);
+
+ // Success case: set partition by key
+ test_partition_db(parts, keyRanges, null, 0, errpfx);
+
+ // Test the exception case: parts != (size of key array + 1)
+ parts++;
+ try {
+ test_partition_db(parts, keyRanges, null, 0, errpfx);
+ throw new Exception("Unexpected exception: setPartitionByRange" +
+ "should fail as parts != (size of key array + 1).");
+ } catch (IllegalArgumentException e) {
+ }
+
+ // Test the exception case: keys == null
+ try {
+ test_partition_db(parts, null, null, 0, errpfx);
+ throw new Exception("Unexpected exception: database open should" +
+ "fail as partition key array and callback are null.");
+ } catch (IllegalArgumentException e) {
+ }
+
+ // Test the exception case: there is no data in the keys
+ try {
+ test_partition_db(parts, new MultipleDataEntry(), null, 0, errpfx);
+ throw new Exception("Unexpected exception: database open should" +
+ "fail as there is no data in the partition keys which is" +
+ "a MultipleDataEntry. ");
+ } catch (IllegalArgumentException e) {
+ }
+
+ // Test the exception case: parts == 1
+ try {
+ test_partition_db(1, null, null, 2, errpfx);
+ throw new Exception("Unexpected exception: database open should" +
+ "fail as the number of partition is set to 1.");
+ } catch (IllegalArgumentException e) {
+ }
+
+ }
+
+ /*
+ * Test creating partition database by callback
+ */
+ @Test public void test13()
+ throws DatabaseException, Exception, FileNotFoundException
+ {
+ String errpfx = "DatabaseTest::test13 ";
+
+ // Success case: set partition by callback
+ PartitionCallback part_func = new PartitionCallback();
+ int parts = 2;
+ test_partition_db(parts, null, part_func, 1, errpfx);
+
+ // Test the exception case: callback and key array are both set
+ MultipleDataEntry keyRanges = new MultipleDataEntry();
+ keyRanges.setData(new byte[1024]);
+ keyRanges.setUserBuffer(1024, true);
+ DatabaseEntry kdbt = new DatabaseEntry();
+ kdbt.setData("b".getBytes());
+ keyRanges.append(kdbt);
+
+ try {
+ test_partition_db(parts, keyRanges, part_func, 2, errpfx);
+ throw new Exception("Unexpected exception: database open should " +
+ "fail as partition callback and key array are both set.");
+ } catch (IllegalArgumentException e) {
+ }
+
+ }
+
+ /*
+ * Test setting the blob directory and threshold value.
+ */
+ @Test public void test14()
+ throws DatabaseException, Exception, FileNotFoundException
+ {
+ TestOptions options = new TestOptions();
+ options.db_config.setErrorPrefix("DatabaseTest::test14 ");
+ options.save_db = true;
+
+ EnvironmentConfig envc = new EnvironmentConfig();
+ envc.setAllowCreate(true);
+ envc.setInitializeCache(true);
+
+ // Test setting the blob directory.
+ String dir[] = {"null", "", "BLOBDIR"};
+ for (int i = -1; i < dir.length; i++) {
+ TestUtils.removeall(true, true, TestUtils.BASETEST_DBDIR,
+ TestUtils.getDBFileName(DATABASETEST_DBNAME));
+ // Set the blob directory.
+ if (i >= 0) {
+ if (dir[i].compareTo("null") == 0)
+ envc.setBlobDir(null);
+ else
+ envc.setBlobDir(new java.io.File(dir[i]));
+ }
+ // Set the blob threshold value.
+ envc.setBlobThreshold(10485760);
+ // Open the env.
+ options.db_env = new Environment(TestUtils.BASETEST_DBFILE, envc);
+ // Verify the blob directory and threshold value.
+ assertEquals(10485760,
+ options.db_env.getConfig().getBlobThreshold());
+ if (i == -1 || dir[i].compareTo("null") == 0)
+ assertNull(options.db_env.getConfig().getBlobDir());
+ else
+ assertEquals(0, options.db_env.getConfig().getBlobDir().
+ toString().compareTo(dir[i]));
+ options.db_env.close();
+ }
+
+ // Test setting the db blob threshold value and open it with no env.
+ test_blob_db(0, null, 3,
+ TestUtils.BASETEST_DBDIR + File.separator + "DBBLOB",
+ 0, "DatabaseTest::test14 ", DatabaseType.BTREE);
+
+ // Test setting the blob directory in the database and then
+ // opening the db within env and verifying the setting is ignored.
+ test_blob_db(3, null, 0, "DBBLOB",
+ 0, "DatabaseTest::test14 ", DatabaseType.BTREE);
+ test_blob_db(3, "ENVBLOB", 0, "DBBLOB",
+ 0, "DatabaseTest::test14 ", DatabaseType.BTREE);
+
+ // Test setting the blob directory in the environment.
+ test_blob_db(3, "ENVBLOB", 0, null,
+ 0, "DatabaseTest::test14 ", DatabaseType.BTREE);
+
+ // Test the db blob threshold value defaults to env blob threshold
+ // value.
+ test_blob_db(3, null, 0, null,
+ 0, "DatabaseTest::test14 ", DatabaseType.BTREE);
+
+ // Test setting db own blob threshold and open it within the env.
+ test_blob_db(4, null, 3, null,
+ 0, "DatabaseTest::test14 ", DatabaseType.HASH);
+
+ // Test putting the data items whose size does not reach the blob
+ // threshold but set as blob data items.
+ test_blob_db(3, null, 0, null,
+ 1, "DatabaseTest::test14 ", DatabaseType.HEAP);
+ }
+
// Check that key/data for 0 - count-1 are already present,
// and write a key/data for count. The key and data are
// both "0123...N" where N == count-1.
@@ -529,6 +722,345 @@ public class DatabaseTest {
else if (options.database == null)
options.database = db;
}
+
+ // Test if setPartitionByRange and setPartitionByCallback work by the
+ // following steps: 1) config the partition by keys and/or callback;
+ // 2) open the database; 3) insert some records; 4) verify the partition
+ // configs; 5) close the database.
+ //
+ // The parameter "apicall" indicates which API is tested. If it is 0,
+ // test setPartitionByRange. If it is 1, test setPartitionByCallback.
+ // Otherwise test both of them.
+ void test_partition_db(int nparts, MultipleDataEntry keys,
+ PartitionHandler funcp, int apicall, String errpfx)
+ throws DatabaseException, FileNotFoundException,
+ IllegalArgumentException
+ {
+ TestUtils.removeall(true, true, TestUtils.BASETEST_DBDIR,
+ TestUtils.getDBFileName(DATABASETEST_DBNAME));
+ TestOptions options = new TestOptions();
+ options.db_config.setErrorPrefix(errpfx);
+ options.db_config.setAllowCreate(true);
+ options.db_config.setType(DatabaseType.BTREE);
+ // Config the partition.
+ // Parameter apicall:
+ // If 0 then call setPartitionByRange;
+ // If 1 then call setPartitionByCallback;
+ // Otherwise call both.
+ if (apicall == 0)
+ options.db_config.setPartitionByRange(nparts, keys);
+ else if (apicall == 1)
+ options.db_config.setPartitionByCallback(nparts, funcp);
+ else {
+ options.db_config.setPartitionByRange(nparts, keys);
+ options.db_config.setPartitionByCallback(nparts, funcp);
+ }
+
+ // Open the database.
+ Database db = new Database(
+ TestUtils.getDBFileName(DATABASETEST_DBNAME),
+ null, options.db_config);
+
+ // Insert some records.
+ String[] records = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j",
+ "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w",
+ "x", "y", "z"};
+ DatabaseEntry ddbt, kdbt;
+ for (int i = 0; i < records.length; i++) {
+ kdbt = new DatabaseEntry();
+ ddbt = new DatabaseEntry();
+ kdbt.setData(records[i].getBytes());
+ ddbt.setData(records[i].getBytes());
+ db.putNoOverwrite(null, kdbt, ddbt);
+ }
+
+ // Verify the number of partitions.
+ assertEquals(nparts, db.getConfig().getPartitionParts());
+
+ // Verify the number of partitioned files.
+ File testdir = new File(TestUtils.BASETEST_DBDIR);
+ File[] flist = testdir.listFiles();
+ int cnt = 0;
+ for (int i = 0; i < Array.getLength(flist); i++) {
+ if (flist[i].getName().substring(0, 6).compareTo("__dbp.") == 0)
+ cnt++;
+ }
+ assertEquals(nparts, cnt);
+
+ // Verify the keys.
+ if (keys != null) {
+ MultipleDataEntry orig_key = new MultipleDataEntry(keys.getData());
+ MultipleDataEntry get_key =new MultipleDataEntry(
+ db.getConfig().getPartitionKeys().getData());
+ String s1, s2;
+ for (kdbt = new DatabaseEntry(), ddbt = new DatabaseEntry();
+ orig_key.next(kdbt) == true;
+ kdbt = new DatabaseEntry(), ddbt = new DatabaseEntry()) {
+ assertEquals(true, get_key.next(ddbt));
+ s1 = new String(kdbt.getData(), kdbt.getOffset(), kdbt.getSize());
+ s2 = new String(ddbt.getData(), ddbt.getOffset(), ddbt.getSize());
+ assertEquals(0, s1.compareTo(s2));
+ }
+ assertEquals(false, get_key.next(ddbt));
+ }
+
+ // Verify the callback.
+ assertEquals(funcp, db.getConfig().getPartitionHandler());
+
+ // Close the database.
+ db.close();
+
+ }
+
+ // Test if the BLOB basic APIs work by the following steps:
+ // 1) configure the blob threshold value and blob directory;
+ // 2) open the database with/without the environment;
+ // 3) insert and verify the blob data by database methods;
+ // 4) insert blob data by cursor, update the blob data and verify
+ // the update by database stream;
+ // 5) verify the blob configs, whether the blobs are created in
+ // expected location and the stats;
+ // 6) close the database and environment.
+ //
+ // The parameter "env_threshold" indicates the blob threshold value
+ // set in the environment and whether the database is opened within
+ // the enviornment. If it is <= 0, open the database without the
+ // enviornment. Otherwise open the database within the enviornment.
+ // The parameter "blobdbt" indicates whether DatabaseEntry.setBlob()
+ // is called on the data items to put. If it is not 0, set the data
+ // items as blob data and make its size < the blob threshold. Otherwise
+ // make the size of the data item reach the threshold and do not set
+ // the data item as blob data.
+ void test_blob_db(int env_threshold, String env_blob_dir,
+ int db_threshold, String db_blob_dir, int blobdbt,
+ String errpfx, DatabaseType dbtype)
+ throws DatabaseException, Exception, FileNotFoundException
+ {
+ // The blob threshold is set at least once either in the environment
+ // or in the database.
+ if (env_threshold <= 0 && db_threshold <= 0)
+ return;
+
+ TestUtils.removeall(true, true, TestUtils.BASETEST_DBDIR,
+ TestUtils.getDBFileName(DATABASETEST_DBNAME));
+ TestOptions options = new TestOptions();
+ options.db_config.setErrorPrefix(errpfx);
+ options.db_config.setAllowCreate(true);
+ options.db_config.setType(dbtype);
+
+ // Configure and open the environment.
+ EnvironmentConfig envc = new EnvironmentConfig();
+ if (env_threshold <= 0)
+ options.db_env = null;
+ else {
+ envc.setAllowCreate(true);
+ envc.setErrorStream(TestUtils.getErrorStream());
+ envc.setInitializeCache(true);
+ envc.setBlobThreshold(env_threshold);
+ if (env_blob_dir != null)
+ envc.setBlobDir(new java.io.File(env_blob_dir));
+ options.db_env = new Environment(TestUtils.BASETEST_DBFILE, envc);
+ }
+
+ // Configure and open the database.
+ if (db_threshold > 0)
+ options.db_config.setBlobThreshold(db_threshold);
+ if (db_blob_dir != null)
+ options.db_config.setBlobDir(new java.io.File(db_blob_dir));
+ if (options.db_env == null)
+ options.database =
+ new Database(TestUtils.getDBFileName(DATABASETEST_DBNAME),
+ null, options.db_config);
+ else {
+ options.database = options.db_env.openDatabase(null,
+ DATABASETEST_DBNAME, null, options.db_config);
+ }
+
+ // Insert and verify some blob data by database method, and then
+ // update the blob data by database stream and verify the update.
+ Cursor cursor = options.database.openCursor(null, null);
+ DatabaseStream dbs;
+ DatabaseStreamConfig dbs_config = new DatabaseStreamConfig();
+ dbs_config.setSyncPerWrite(true);
+ assertEquals(true, dbs_config.getSyncPerWrite());
+ assertEquals(false, dbs_config.getReadOnly());
+ String[] records = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j",
+ "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w",
+ "x", "y", "z"};
+ DatabaseEntry ddbt, kdbt, sdbt;
+ String data;
+ for (int i = 0; i < records.length; i++) {
+ kdbt = new DatabaseEntry();
+ ddbt = new DatabaseEntry();
+ kdbt.setData(records[i].getBytes());
+ data = records[i];
+ if (blobdbt != 0) {
+ ddbt.setBlob(true);
+ assertTrue(ddbt.getBlob());
+ } else {
+ for (int j = 1;
+ j < options.database.getConfig().getBlobThreshold(); j++)
+ data = data + records[i];
+ }
+ ddbt.setData(data.getBytes());
+ if (dbtype == DatabaseType.HEAP)
+ options.database.append(null, kdbt, ddbt);
+ else
+ options.database.put(null, kdbt, ddbt);
+
+ // Verify the blob data by database get method.
+ assertEquals(OperationStatus.SUCCESS,
+ options.database.get(null, kdbt, ddbt, null));
+ assertArrayEquals(data.getBytes(), ddbt.getData());
+
+ // Update the blob data by database stream and verify the update.
+ assertEquals(OperationStatus.SUCCESS,
+ cursor.getSearchKey(kdbt, ddbt, null));
+ dbs = cursor.openDatabaseStream(dbs_config);
+ assertEquals(data.length(), dbs.size());
+ sdbt = new DatabaseEntry("abc".getBytes());
+ assertEquals(OperationStatus.SUCCESS, dbs.write(sdbt, dbs.size()));
+ assertEquals(OperationStatus.SUCCESS,
+ dbs.read(sdbt, 0, (int)dbs.size()));
+ assertArrayEquals((data + "abc").getBytes(), sdbt.getData());
+ dbs.close();
+ }
+ cursor.close();
+
+ // Insert the blob data by cursor, update the blob data by database
+ // stream and verify the update.
+ if (dbtype != DatabaseType.HEAP) {
+ cursor = options.database.openCursor(null, null);
+ kdbt = new DatabaseEntry("abc".getBytes());
+ ddbt = new DatabaseEntry("abc".getBytes());
+ ddbt.setBlob(true);
+ assertEquals(true, ddbt.getBlob());
+ assertEquals(OperationStatus.SUCCESS,
+ cursor.putKeyFirst(kdbt, ddbt));
+
+ dbs = cursor.openDatabaseStream(dbs_config);
+ assertEquals(3, dbs.size());
+ sdbt = new DatabaseEntry("defg".getBytes());
+ assertEquals(OperationStatus.SUCCESS, dbs.write(sdbt, dbs.size()));
+
+ // Verify datbase stream writing/reading with
+ // partial DatabaseEntry will fail.
+ try {
+ kdbt.setPartial(true);
+ assertEquals(true, kdbt.getPartial());
+ dbs.write(kdbt, 0);
+ throw new Exception("database stream write/read"
+ + "with partial DatabaseEntry should fail");
+ } catch (IllegalArgumentException e) {
+ }
+
+ try {
+ dbs.read(kdbt, 0, (int)dbs.size());
+ throw new Exception("database stream read"
+ + "with partial DatabaseEntry should fail");
+ } catch (IllegalArgumentException e) {
+ }
+
+ dbs.close();
+
+ // Verify the update and that database stream can not write when it
+ // is configured to be read-only.
+ dbs_config.setReadOnly(true);
+ assertEquals(true, dbs_config.getReadOnly());
+ dbs = cursor.openDatabaseStream(dbs_config);
+ assertEquals(7, dbs.size());
+ assertEquals(OperationStatus.SUCCESS,
+ dbs.read(sdbt, 0, (int)dbs.size()));
+ assertArrayEquals("abcdefg".getBytes(), sdbt.getData());
+ try {
+ dbs.write(sdbt, 7);
+ throw new Exception("database stream write should fail"
+ + "as it is configured to be read-only");
+ } catch (IllegalArgumentException e) {
+ }
+ dbs.close();
+
+ cursor.close();
+ }
+
+ // Verify the blob config of the enviornment.
+ if (options.db_env != null && env_threshold > 0) {
+ assertEquals(env_threshold,
+ options.db_env.getConfig().getBlobThreshold());
+ if (env_blob_dir == null)
+ assertNull(options.db_env.getConfig().getBlobDir());
+ else
+ assertEquals(0, options.db_env.getConfig().
+ getBlobDir().toString().compareTo(env_blob_dir));
+ }
+
+ // Verify the blob config of the database.
+ assertEquals(db_threshold > 0 ? db_threshold : env_threshold,
+ options.database.getConfig().getBlobThreshold());
+ String blrootdir;
+ if (options.db_env != null) {
+ if (env_blob_dir == null)
+ blrootdir = "__db_bl";
+ else
+ blrootdir = env_blob_dir;
+ } else if (db_blob_dir == null) {
+ blrootdir = "__db_bl";
+ } else {
+ blrootdir = db_blob_dir;
+ }
+ assertEquals(0, options.database.getConfig().
+ getBlobDir().toString().compareTo(blrootdir));
+
+ // Verify the blobs are created in the expected location.
+ // This part of test is disabled since the Database.getBlobSubDir()
+ // is not expsed to users.
+ //if (options.db_env != null)
+ // blrootdir = options.db_env.getHome().toString() + "/" + blrootdir;
+ //assertNotNull(options.database.getBlobSubDir().toString());
+ //File blobdir = new File(blrootdir + "/" +
+ // options.database.getBlobSubDir().toString());
+ //assertTrue(blobdir.listFiles().length > records.length);
+
+ // Verify the stats.
+ if (dbtype == DatabaseType.HASH) {
+ HashStats stats = (HashStats)options.database.getStats(null, null);
+ assertEquals(records.length + 1, stats.getNumBlobs());
+ } else if (dbtype == DatabaseType.HEAP) {
+ HeapStats stats = (HeapStats)options.database.getStats(null, null);
+ assertEquals(records.length, stats.getHeapNumBlobs());
+ } else {
+ BtreeStats stats =
+ (BtreeStats)options.database.getStats(null, null);
+ assertEquals(records.length + 1, stats.getNumBlobs());
+ }
+
+ // Close the database and set up the blob directory configuration
+ // used in removing the database.
+ options.database.close();
+ if (options.db_env != null)
+ blrootdir = TestUtils.BASETEST_DBDIR + File.separator + blrootdir;
+ options.db_config.setBlobDir(new File(blrootdir));
+
+ // TestUtils.removeall does not work on the blob database since it
+ // removes the database with the default database configuration. So
+ // remove the blob database with blob configuration here.
+ Database.remove(TestUtils.getDBFileName(DATABASETEST_DBNAME),
+ null, options.db_config);
+
+ // All blobs are deleted but the blob directory remains after db
+ // remove. Verify it and delete the blob directory.
+ File[] files = options.db_config.getBlobDir().listFiles();
+ assertTrue(files.length > 0);
+ for (int i = 0; i < files.length; i++) {
+ if (files[i].isDirectory())
+ assertEquals(0, files[i].listFiles().length);
+ }
+ TestUtils.removeDir(blrootdir);
+
+ // Close the environment.
+ if (options.db_env != null)
+ options.db_env.close();
+ }
}
@@ -561,3 +1093,16 @@ class TestOptions
}
}
+
+class PartitionCallback implements PartitionHandler
+{
+ public int partition(Database db, DatabaseEntry key)
+ {
+ String data = new String(key.getData());
+
+ if (data.compareTo("d") >= 0)
+ return 1;
+ else
+ return 0;
+ }
+}
diff --git a/test/java/junit/src/com/sleepycat/db/test/EncryptTest.java b/test/java/junit/src/com/sleepycat/db/test/EncryptTest.java
index 57c6faba..89bbd197 100644
--- a/test/java/junit/src/com/sleepycat/db/test/EncryptTest.java
+++ b/test/java/junit/src/com/sleepycat/db/test/EncryptTest.java
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved.
*
*/
diff --git a/test/java/junit/src/com/sleepycat/db/test/EnvRegionSizeTest.java b/test/java/junit/src/com/sleepycat/db/test/EnvRegionSizeTest.java
index 4259c6df..3e1e9033 100644
--- a/test/java/junit/src/com/sleepycat/db/test/EnvRegionSizeTest.java
+++ b/test/java/junit/src/com/sleepycat/db/test/EnvRegionSizeTest.java
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 2011, 2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2015 Oracle and/or its affiliates. All rights reserved.
*
*/
diff --git a/test/java/junit/src/com/sleepycat/db/test/HashCompareTest.java b/test/java/junit/src/com/sleepycat/db/test/HashCompareTest.java
index 18d11f57..7be5e6c4 100644
--- a/test/java/junit/src/com/sleepycat/db/test/HashCompareTest.java
+++ b/test/java/junit/src/com/sleepycat/db/test/HashCompareTest.java
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved.
*
*/
diff --git a/test/java/junit/src/com/sleepycat/db/test/LogCursorTest.java b/test/java/junit/src/com/sleepycat/db/test/LogCursorTest.java
index b6a5b08b..25476832 100644
--- a/test/java/junit/src/com/sleepycat/db/test/LogCursorTest.java
+++ b/test/java/junit/src/com/sleepycat/db/test/LogCursorTest.java
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved.
*
*/
diff --git a/test/java/junit/src/com/sleepycat/db/test/MultipleCursorTest.java b/test/java/junit/src/com/sleepycat/db/test/MultipleCursorTest.java
index e7374d31..5854c8cd 100644
--- a/test/java/junit/src/com/sleepycat/db/test/MultipleCursorTest.java
+++ b/test/java/junit/src/com/sleepycat/db/test/MultipleCursorTest.java
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved.
*
*/
diff --git a/test/java/junit/src/com/sleepycat/db/test/PartialGetTest.java b/test/java/junit/src/com/sleepycat/db/test/PartialGetTest.java
index 35d97721..791032fa 100644
--- a/test/java/junit/src/com/sleepycat/db/test/PartialGetTest.java
+++ b/test/java/junit/src/com/sleepycat/db/test/PartialGetTest.java
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved.
*
*/
diff --git a/test/java/junit/src/com/sleepycat/db/test/PriorityTest.java b/test/java/junit/src/com/sleepycat/db/test/PriorityTest.java
index 8f8d7cf4..506252ab 100644
--- a/test/java/junit/src/com/sleepycat/db/test/PriorityTest.java
+++ b/test/java/junit/src/com/sleepycat/db/test/PriorityTest.java
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved.
*
*/
diff --git a/test/java/junit/src/com/sleepycat/db/test/RepmgrConfigTest.java b/test/java/junit/src/com/sleepycat/db/test/RepmgrConfigTest.java
index f8d8b789..b7423484 100644
--- a/test/java/junit/src/com/sleepycat/db/test/RepmgrConfigTest.java
+++ b/test/java/junit/src/com/sleepycat/db/test/RepmgrConfigTest.java
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved.
*
*/
diff --git a/test/java/junit/src/com/sleepycat/db/test/RepmgrElectionTest.java b/test/java/junit/src/com/sleepycat/db/test/RepmgrElectionTest.java
index e2bf6a3e..d25d729b 100644
--- a/test/java/junit/src/com/sleepycat/db/test/RepmgrElectionTest.java
+++ b/test/java/junit/src/com/sleepycat/db/test/RepmgrElectionTest.java
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved.
*/
package com.sleepycat.db.test;
diff --git a/test/java/junit/src/com/sleepycat/db/test/RepmgrSiteTest.java b/test/java/junit/src/com/sleepycat/db/test/RepmgrSiteTest.java
index 2024169d..4a5955e4 100644
--- a/test/java/junit/src/com/sleepycat/db/test/RepmgrSiteTest.java
+++ b/test/java/junit/src/com/sleepycat/db/test/RepmgrSiteTest.java
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 2011, 2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2015 Oracle and/or its affiliates. All rights reserved.
*
* $Id$
*
@@ -18,6 +18,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.io.File;
+import java.io.FileNotFoundException;
import com.sleepycat.db.*;
public class RepmgrSiteTest extends EventHandlerAdapter
@@ -147,6 +148,127 @@ public class RepmgrSiteTest extends EventHandlerAdapter
env.close();
}
+ @Test public void testPartialRep() throws Exception
+ {
+ // Start up master.
+ File mHomeDir = new File(homedirName + File.separator + "master");
+ mHomeDir.mkdir();
+ ReplicationManagerSiteConfig mConf =
+ new ReplicationManagerSiteConfig(host, port);
+ mConf.setLocalSite(true);
+ mConf.setGroupCreator(true);
+ envConfig.addReplicationManagerSite(mConf);
+ long mport = port;
+
+ Environment mEnv = new Environment(mHomeDir, envConfig);
+
+ mEnv.replicationManagerStart(4,
+ ReplicationManagerStartPolicy.REP_MASTER);
+
+ // Set up the environments for the client sites.
+ ReplicationManagerSiteConfig hConf =
+ new ReplicationManagerSiteConfig(host, port);
+ hConf.setBootstrapHelper(true);
+ File cHomeDir1 = new File(homedirName + File.separator + "client1");
+ cHomeDir1.mkdir();
+ port++;
+ ReplicationManagerSiteConfig cConf1 =
+ new ReplicationManagerSiteConfig(host, port);
+ cConf1.setLocalSite(true);
+ EnvironmentConfig cEnvConfig1 = initEnvConfig();
+ cEnvConfig1.addReplicationManagerSite(cConf1);
+ cEnvConfig1.addReplicationManagerSite(hConf);
+ // Set the client 1 site as a partial view.
+ cEnvConfig1.setReplicationView(new RepViewCallback());
+ Environment cEnv1 = new Environment(cHomeDir1, cEnvConfig1);
+
+ File cHomeDir2 = new File(homedirName + File.separator + "client2");
+ cHomeDir2.mkdir();
+ port++;
+ ReplicationManagerSiteConfig cConf2 =
+ new ReplicationManagerSiteConfig(host, port);
+ cConf2.setLocalSite(true);
+ EnvironmentConfig cEnvConfig2 = initEnvConfig();
+ cEnvConfig2.addReplicationManagerSite(cConf2);
+ cEnvConfig2.addReplicationManagerSite(hConf);
+ // Set the client 2 site as a full view.
+ cEnvConfig2.setReplicationView(null);
+ Environment cEnv2 = new Environment(cHomeDir2, cEnvConfig2);
+
+ // Create 2 db files on the master site.
+ DatabaseConfig db_config = new DatabaseConfig();
+ db_config.setErrorStream(TestUtils.getErrorStream());
+ db_config.setErrorPrefix("RepmgrSiteTest::testPartialRep ");
+ db_config.setType(DatabaseType.BTREE);
+ db_config.setAllowCreate(true);
+ db_config.setTransactional(true);
+
+ Database db1 = mEnv.openDatabase(null, "db1.db", null, db_config);
+ Database db2 = mEnv.openDatabase(null, "db2.db", null, db_config);
+ db1.close();
+ db2.close();
+
+ // Start the client sites.
+ cEnv1.replicationManagerStart(4,
+ ReplicationManagerStartPolicy.REP_CLIENT);
+ assertTrue(waitForStartUpDone(cEnv1));
+ cEnv2.replicationManagerStart(4,
+ ReplicationManagerStartPolicy.REP_CLIENT);
+ assertTrue(waitForStartUpDone(cEnv2));
+
+ // Verify that the database file db1.db is replicated to both client
+ // sites, but db2.db is replicated only to the client 2 site.
+ db_config.setAllowCreate(false);
+ db1 = cEnv1.openDatabase(null, "db1.db", null, db_config);
+ try {
+ db2 = cEnv1.openDatabase(null, "db2.db", null, db_config);
+ throw new Exception();
+ } catch (FileNotFoundException e) {
+ }
+ db1.close();
+
+ db1 = cEnv2.openDatabase(null, "db1.db", null, db_config);
+ db2 = cEnv2.openDatabase(null, "db2.db", null, db_config);
+ db1.close();
+ db2.close();
+
+ // Verify the clients are views locally and from remote site.
+ ReplicationManagerSiteInfo[] siteLists =
+ mEnv.getReplicationManagerSiteList();
+ assertEquals(2, siteLists.length);
+ assertEquals(true, siteLists[0].isView());
+ assertEquals(true, siteLists[1].isView());
+ ReplicationStats repStats =
+ cEnv1.getReplicationStats(StatsConfig.DEFAULT);
+ assertEquals(true, repStats.getView());
+ repStats = cEnv2.getReplicationStats(StatsConfig.DEFAULT);
+ assertEquals(true, repStats.getView());
+
+ // Verify the master is not a view locally or from remote site.
+ siteLists = cEnv1.getReplicationManagerSiteList();
+ assertEquals(2, siteLists.length);
+ int i;
+ for (i = 0; i < siteLists.length; i++) {
+ if (siteLists[i].addr.port == mport)
+ break;
+ }
+ assertTrue(i < siteLists.length);
+ assertEquals(false, siteLists[i].isView());
+ repStats = mEnv.getReplicationStats(StatsConfig.DEFAULT);
+ assertEquals(false, repStats.getView());
+
+ // Get the replication manager statistics.
+ ReplicationManagerStats masterStats =
+ mEnv.getReplicationManagerStats(StatsConfig.DEFAULT);
+ assertEquals(1, masterStats.getSiteParticipants());
+ assertEquals(3, masterStats.getSiteTotal());
+ assertEquals(2, masterStats.getSiteViews());
+
+ cEnv2.close();
+ cEnv1.close();
+ mEnv.close();
+ }
+
@Test public void testRepmgrSiteConfig() throws Exception
{
// Start up master.
@@ -339,3 +461,15 @@ public class RepmgrSiteTest extends EventHandlerAdapter
mEnv.close();
}
}
+
+class RepViewCallback implements ReplicationViewHandler
+{
+ public boolean partial_view(Environment dbenv, String name, int flags)
+ throws DatabaseException
+ {
+ if (name.compareTo("db1.db") == 0)
+ return true;
+ else
+ return false;
+ }
+}
diff --git a/test/java/junit/src/com/sleepycat/db/test/RepmgrStartupTest.java b/test/java/junit/src/com/sleepycat/db/test/RepmgrStartupTest.java
index 2897752e..f2014d33 100644
--- a/test/java/junit/src/com/sleepycat/db/test/RepmgrStartupTest.java
+++ b/test/java/junit/src/com/sleepycat/db/test/RepmgrStartupTest.java
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved.
*
*/
@@ -117,6 +117,21 @@ public class RepmgrStartupTest extends EventHandlerAdapter
try {
// start replication manager
dbenv.replicationManagerStart(3, ReplicationManagerStartPolicy.REP_MASTER);
+ EnvironmentConfig cfg = dbenv.getConfig();
+ assertEquals(cfg.getReplicationManagerIncomingQueueMax(), 100L * 1024L * 1024L);
+ long gigabyte = 1024L * 1024L * 1024L;
+ long megabyte = 1024L * 1024L;
+ // Test setting repmgr incoming queue size > 1GB.
+ cfg.setReplicationManagerIncomingQueueMax(123456L * gigabyte + 654321L);
+ dbenv.setConfig(cfg);
+ cfg = dbenv.getConfig();
+ assertEquals(cfg.getReplicationManagerIncomingQueueMax(), 123456L * gigabyte + 654321L);
+ // Test setting repmgr incoming queue size < 1GB.
+ cfg.setReplicationManagerIncomingQueueMax(10L * megabyte);
+ dbenv.setConfig(cfg);
+ cfg = dbenv.getConfig();
+ assertEquals(cfg.getReplicationManagerIncomingQueueMax(), 10L * megabyte);
+
} catch(DatabaseException dbe) {
fail("Unexpected database exception came from replicationManagerStart." + dbe);
}
diff --git a/test/java/junit/src/com/sleepycat/db/test/TestUtils.java b/test/java/junit/src/com/sleepycat/db/test/TestUtils.java
index 083b1123..22bff5dc 100644
--- a/test/java/junit/src/com/sleepycat/db/test/TestUtils.java
+++ b/test/java/junit/src/com/sleepycat/db/test/TestUtils.java
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved.
*
*/
@@ -136,10 +136,13 @@ public class TestUtils
} else if(!deldir.isDirectory()) {
return false;
} else {
- // The following will fail if the directory contains sub-dirs.
File[] contents = deldir.listFiles();
- for (int i = 0; i < contents.length; i++)
- contents[i].delete();
+ for (int i = 0; i < contents.length; i++) {
+ if (contents[i].isDirectory())
+ removeDir(contents[i].toString());
+ else
+ contents[i].delete();
+ }
deldir.delete();
}
} catch (Exception e) {
diff --git a/test/java/junit/src/com/sleepycat/db/test/VerboseConfigTest.java b/test/java/junit/src/com/sleepycat/db/test/VerboseConfigTest.java
index 7e66d556..e2eb264e 100644
--- a/test/java/junit/src/com/sleepycat/db/test/VerboseConfigTest.java
+++ b/test/java/junit/src/com/sleepycat/db/test/VerboseConfigTest.java
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved.
*/
package com.sleepycat.db.test;