// Path: src/test/java/be/bagofwords/db/BaseTestDataInterface.java
// public class BaseTestDataInterface {
// 
//     private static long count = System.currentTimeMillis();
// 
//     @Parameterized.Parameters(name = "{0} {1}")
//     public static List<Object[]> getManagers() throws IOException {
//         List<Object[]> result = new ArrayList<>();
// 
//         List<DatabaseBackendType> backendTypes = new ArrayList<>();
//         backendTypes.add(DatabaseBackendType.MEMORY);
//         backendTypes.add(DatabaseBackendType.REMOTE);
//         backendTypes.add(DatabaseBackendType.FILE);
// 
//         for (DatabaseBackendType backendType : backendTypes) {
//             result.add(new Object[]{DatabaseCachingType.CACHED_AND_BLOOM, backendType});
//             result.add(new Object[]{DatabaseCachingType.CACHED, backendType});
//             result.add(new Object[]{DatabaseCachingType.DIRECT, backendType});
//         }
//         return result;
//     }
// 
//     protected DatabaseBackendType backendType;
//     protected DatabaseCachingType type;
//     protected DataInterfaceFactory dataInterfaceFactory;
// 
//     private RemoteDataInterfaceServer remoteDataInterfaceServer; //only created for remote backend
//     private FileDataInterfaceFactory dataInterfaceServerFactory; //only created for remote backend
//     private ApplicationContext context;
// 
//     public BaseTestDataInterface(DatabaseCachingType type, DatabaseBackendType backendType) throws Exception {
//         this.backendType = backendType;
//         this.type = type;
//     }
// 
//     @Before
//     public void setUp() throws Exception {
//         HashMap<String, String> config = new HashMap<>();
//         config.put("data_directory", "/tmp/dbServer/" + System.currentTimeMillis());
//         config.put("socket.host", "localhost");
//         config.put("socket.port", "1308");
//         context = new ApplicationContext(config);
//         context.registerBean(MinimalApplicationDependencies.class);
//         DataInterfaceFactoryFactory dataInterfaceFactoryFactory = new DataInterfaceFactoryFactory(context);
//         if (backendType == DatabaseBackendType.REMOTE) {
//             dataInterfaceServerFactory = context.getBean(FileDataInterfaceFactory.class);
//             remoteDataInterfaceServer = context.getBean(RemoteDataInterfaceServer.class);
//             context.registerBean(SocketServer.class);
//         }
//         dataInterfaceFactory = dataInterfaceFactoryFactory.createFactory(backendType);
//     }
// 
//     @After
//     public void closeFactory() throws IOException {
//         if (dataInterfaceFactory != null) {
//             dataInterfaceFactory.closeAllInterfaces();
//         }
//         context.terminate();
//         File directory = new File("/tmp/dbServer");
//         if (directory.exists()) {
//             FileUtils.deleteDirectory(directory);
//         }
//     }
// 
//     public void createDataInterfaceFactory(DataInterfaceFactoryFactory dataInterfaceFactoryFactory) {
//         this.dataInterfaceFactory = dataInterfaceFactoryFactory.createFactory(backendType);
//     }
// 
//     protected DataInterface<Long> createCountDataInterface(String name) {
//         return dataInterfaceFactory.dataInterface(name + "_" + (count++), Long.class).combinator(new LongCombinator()).serializer(new LongObjectSerializer()).caching(type).create();
//     }
// 
//     protected <T> DataInterfaceConfig<T> createDataInterface(String name, Class<T> _class) {
//         return dataInterfaceFactory.dataInterface(name + "_" + (count++), _class);
//     }
// 
// }
// 
// Path: src/main/java/be/bagofwords/db/DatabaseBackendType.java
// public enum DatabaseBackendType {
// 
//     FILE, MEMORY, REMOTE
// 
// }
// 
// Path: src/main/java/be/bagofwords/db/DatabaseCachingType.java
// public enum DatabaseCachingType {
// 
//     DIRECT(false, false), CACHED(true, false), CACHED_AND_BLOOM(true, true), BLOOM(false, true);
// 
//     private boolean useCache;
//     private boolean useBloomFilter;
// 
//     DatabaseCachingType(boolean useCache, boolean useBloomFilter) {
//         this.useCache = useCache;
//         this.useBloomFilter = useBloomFilter;
//     }
// 
//     public boolean useCache() {
//         return useCache;
//     }
// 
//     public boolean useBloomFilter() {
//         return useBloomFilter;
//     }
// }


import be.bagofwords.db.BaseTestDataInterface;
import be.bagofwords.db.DatabaseBackendType;
import be.bagofwords.db.DatabaseCachingType;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
package be.bagofwords.db.experimental.id;



@RunWith(Parameterized.class)
public class TestIdDataInterface extends BaseTestDataInterface {

    public TestIdDataInterface(DatabaseCachingType type, DatabaseBackendType backendType) throws Exception {
        super(type, backendType);
    }

    @Test
    public void testWriteRead() {
        IdDataInterface<User> userDI = dataInterfaceFactory.createIdDataInterface("user", User.class);
        String id = "my-id";
        User user = new User(id, "Koen", "Deschacht");
        userDI.write(user);
        userDI.flush();
// Path: src/test/java/be/bagofwords/db/BaseTestDataInterface.java
// public class BaseTestDataInterface {
// 
//     private static long count = System.currentTimeMillis();
// 
//     @Parameterized.Parameters(name = "{0} {1}")
//     public static List<Object[]> getManagers() throws IOException {
//         List<Object[]> result = new ArrayList<>();
// 
//         List<DatabaseBackendType> backendTypes = new ArrayList<>();
//         backendTypes.add(DatabaseBackendType.MEMORY);
//         backendTypes.add(DatabaseBackendType.REMOTE);
//         backendTypes.add(DatabaseBackendType.FILE);
// 
//         for (DatabaseBackendType backendType : backendTypes) {
//             result.add(new Object[]{DatabaseCachingType.CACHED_AND_BLOOM, backendType});
//             result.add(new Object[]{DatabaseCachingType.CACHED, backendType});
//             result.add(new Object[]{DatabaseCachingType.DIRECT, backendType});
//         }
//         return result;
//     }
// 
//     protected DatabaseBackendType backendType;
//     protected DatabaseCachingType type;
//     protected DataInterfaceFactory dataInterfaceFactory;
// 
//     private RemoteDataInterfaceServer remoteDataInterfaceServer; //only created for remote backend
//     private FileDataInterfaceFactory dataInterfaceServerFactory; //only created for remote backend
//     private ApplicationContext context;
// 
//     public BaseTestDataInterface(DatabaseCachingType type, DatabaseBackendType backendType) throws Exception {
//         this.backendType = backendType;
//         this.type = type;
//     }
// 
//     @Before
//     public void setUp() throws Exception {
//         HashMap<String, String> config = new HashMap<>();
//         config.put("data_directory", "/tmp/dbServer/" + System.currentTimeMillis());
//         config.put("socket.host", "localhost");
//         config.put("socket.port", "1308");
//         context = new ApplicationContext(config);
//         context.registerBean(MinimalApplicationDependencies.class);
//         DataInterfaceFactoryFactory dataInterfaceFactoryFactory = new DataInterfaceFactoryFactory(context);
//         if (backendType == DatabaseBackendType.REMOTE) {
//             dataInterfaceServerFactory = context.getBean(FileDataInterfaceFactory.class);
//             remoteDataInterfaceServer = context.getBean(RemoteDataInterfaceServer.class);
//             context.registerBean(SocketServer.class);
//         }
//         dataInterfaceFactory = dataInterfaceFactoryFactory.createFactory(backendType);
//     }
// 
//     @After
//     public void closeFactory() throws IOException {
//         if (dataInterfaceFactory != null) {
//             dataInterfaceFactory.closeAllInterfaces();
//         }
//         context.terminate();
//         File directory = new File("/tmp/dbServer");
//         if (directory.exists()) {
//             FileUtils.deleteDirectory(directory);
//         }
//     }
// 
//     public void createDataInterfaceFactory(DataInterfaceFactoryFactory dataInterfaceFactoryFactory) {
//         this.dataInterfaceFactory = dataInterfaceFactoryFactory.createFactory(backendType);
//     }
// 
//     protected DataInterface<Long> createCountDataInterface(String name) {
//         return dataInterfaceFactory.dataInterface(name + "_" + (count++), Long.class).combinator(new LongCombinator()).serializer(new LongObjectSerializer()).caching(type).create();
//     }
// 
//     protected <T> DataInterfaceConfig<T> createDataInterface(String name, Class<T> _class) {
//         return dataInterfaceFactory.dataInterface(name + "_" + (count++), _class);
//     }
// 
// }
// 
// Path: src/main/java/be/bagofwords/db/DatabaseBackendType.java
// public enum DatabaseBackendType {
// 
//     FILE, MEMORY, REMOTE
// 
// }
// 
// Path: src/main/java/be/bagofwords/db/DatabaseCachingType.java
// public enum DatabaseCachingType {
// 
//     DIRECT(false, false), CACHED(true, false), CACHED_AND_BLOOM(true, true), BLOOM(false, true);
// 
//     private boolean useCache;
//     private boolean useBloomFilter;
// 
//     DatabaseCachingType(boolean useCache, boolean useBloomFilter) {
//         this.useCache = useCache;
//         this.useBloomFilter = useBloomFilter;
//     }
// 
//     public boolean useCache() {
//         return useCache;
//     }
// 
//     public boolean useBloomFilter() {
//         return useBloomFilter;
//     }
// }


// Path: src/test/java/be/bagofwords/db/experimental/id/TestIdDataInterface.java
import be.bagofwords.db.BaseTestDataInterface;
import be.bagofwords.db.DatabaseBackendType;
import be.bagofwords.db.DatabaseCachingType;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

package be.bagofwords.db.experimental.id;



@RunWith(Parameterized.class)
public class TestIdDataInterface extends BaseTestDataInterface {

    public TestIdDataInterface(DatabaseCachingType type, DatabaseBackendType backendType) throws Exception {
        super(type, backendType);
    }

    @Test
    public void testWriteRead() {
        IdDataInterface<User> userDI = dataInterfaceFactory.createIdDataInterface("user", User.class);
        String id = "my-id";
        User user = new User(id, "Koen", "Deschacht");
        userDI.write(user);
        userDI.flush();
        User readUser = userDI.read(id);