Hi,

I just started to explore the new MVStore because it's support for versions.

But I ran into some strange behaviour with the content of MVMap:s when 
using MVStore.rollback().

It seems like a non-map that was removed is empty after rollback.

Reproduce:
1) Open a new map and insert one entry (key1=value1)
2) Commit
3) Remove map
4) Rollback
5) The map seems to exist again but when opening it it's empty

Is this a bug or am I missing something?

I'm testing this against h2-1.4.180.
See attached Java-code for a jUnit test reproducing it.


Kind regards,
Konrad

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/d/optout.
package test.mvstore;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import org.h2.mvstore.MVStore;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.*;

/**
 * jUnit test of MVStore behavior when doing rollback after removing a map.
 * 
 * Tested on h2-1.4.180
 * 
 * @author Konrad Eriksson <[email protected]>
 *
 */
public class RollbackTest {
	static String filename = "rollbacktest.mvstore";
	static String mapName = "test";
	MVStore store;
	
	@Before
	public void openStore() {
		File file = new File(filename);
		if(file.isFile())
			file.delete();
		store = new MVStore.Builder().fileName(filename).autoCommitDisabled().open();	
	}
	
	@After
	public void closeStore() {
		store.close();
	}
	
	@Test
	public void rollbackAfterRemoveMap() {
		assertEquals(0L, store.getCurrentVersion());
		
		store.openMap(mapName).put("key1", "value1");
		store.commit();
		assertEquals(map("key1", "value1"), store.openMap(mapName));
		assertEquals(1L, store.getCurrentVersion());
		
		store.removeMap(store.openMap(mapName));
		assertFalse(store.hasMap(mapName));
		
		store.rollback();
		assertTrue(store.hasMap(mapName));
		// This assert fails with: java.lang.AssertionError: expected:<{key1=value1}> but was:<>
		assertEquals(map("key1", "value1"), store.openMap(mapName));
	}
	
	private Map<String, String> map(String key, String value) {
		Map<String, String> map = new HashMap<String, String>(1);
		map.put(key, value);
		return map;
	}
	
}

Reply via email to