-\r
- public static File createTmpDir()\r
- {\r
- String tmp = System.getenv("tmp");\r
- if (tmp==null) tmp = "c:/temp";\r
- Random r = new Random();\r
- String randomName = "tmp-"+(r.nextInt(10000)+10000);\r
- File tmpDir = new File(tmp+"/"+randomName);\r
- Boolean ok = tmpDir.mkdirs();\r
- assertTrue( ok );\r
- return tmpDir;\r
- } \r
-\r
- public boolean isKeyShortEnough(Binding binding, Object value) throws AdaptException {\r
- String key = (String) Bindings.adapt(value, binding, Bindings.STR_VARIANT); \r
- return key.length()<=200;\r
- }\r
-\r
- public @Test void testWireAccessor() throws Exception {\r
- System.out.println("Wire accessor test");\r
- \r
- // TODO: Fix this!\r
- if (true) return;\r
-\r
- for (int i=0; i<10000; i++) {\r
- Bindings.defaultBindingRepository.clear();\r
- Bindings.bindingRepository.clear();\r
- Bindings.serializerRepository.clear();\r
- repository.clear();\r
- System.out.println(i+": ");\r
- rv = new RandomValue(i); \r
- rv.refereableRecords = false;\r
- Datatype type = rv.randomType(0, 3);\r
- Binding binding = scheme.getBindingUnchecked(type);\r
- Object instance = binding.accept(rv);\r
-// System.out.println(binding.printValue(instance, true));\r
- Accessor accessor = Accessors.getAccessor(binding, instance);\r
- \r
- WireServer wireServer = new WireServer(accessor);\r
- Server server = new Server(0, wireServer.getMethodInterface());\r
- WireClient wireClient = new WireClient();\r
- Client client = new Client(InetAddress.getByName("localhost"), server.getPort(), wireClient.getClientMethodInterface());\r
- wireClient.setServerMethodInterface(client.getConnection().getRemoteMethodInterface());\r
- Accessor remoteAccessor = (Accessor) wireClient.getAccessor(null);\r
- testAccessor( remoteAccessor, false );\r
- \r
- wireClient.close();\r
- client.close();\r
- server.close();\r
- }\r
- \r
- }\r
- \r
- public @Test void testBinaryAccessor() throws Exception {\r
- System.out.println("Test Binary Memory:");\r
- \r
- Datatype type = Datatypes.VARIANT;\r
- Binding binding = scheme.getBindingUnchecked( type );\r
- Serializer s = binding.serializer();\r
- TObjectIntHashMap<Object> identities = new TObjectIntHashMap<Object>();\r
- \r
- for (int i=0; i<10000; i++) {\r
- Bindings.defaultBindingRepository.clear();\r
- Bindings.bindingRepository.clear();\r
- Bindings.serializerRepository.clear(); \r
- repository.clear(); \r
- rv = new RandomValue(i); \r
- rv.getRandom().nextLong();\r
- rv.refereableRecords = false;\r
- System.out.println(i+": ");\r
- BinaryMemory ram = new BinaryMemory(0);\r
- Object instance = binding.accept(rv);\r
- \r
- binding.assertInstaceIsValid(instance);\r
-// System.out.println(instance);\r
- \r
- identities.clear();\r
- int size = s.getSize(instance, identities);\r
- \r
- ram.setLength(size); \r
- ram.position(0);\r
- identities.clear();\r
- s.serialize(ram, identities, instance);\r
- identities.clear();\r
-\r
- ram.position(0L);\r
- Object instance2 = s.deserialize(ram);\r
- assertTrue( binding.equals(instance, instance2) );\r
- binding.assertInstaceIsValid(instance2);\r
- \r
- VariantAccessor a = (VariantAccessor) Accessors.getAccessor(ram, type);\r
- \r
- testAccessor(a);\r
- \r
- }\r
- \r
- }\r
-\r
- \r
- public @Test void testJavaAccessor() throws Exception {\r
- System.out.println("Test Java Objects:");\r
- for (int i=0; i<10000; i++) {\r
- Bindings.defaultBindingRepository.clear();\r
- Bindings.bindingRepository.clear();\r
- Bindings.serializerRepository.clear();\r
- repository.clear(); \r
- System.out.println(i+": ");\r
- rv = new RandomValue(i); \r
- rv.refereableRecords = false;\r
- Datatype type = rv.randomType(0, 3);\r
- Binding binding = scheme.getBindingUnchecked(type);\r
- Object instance = binding.accept(rv);\r
-// System.out.println(binding.printValue(instance, true));\r
- Accessor accessor = Accessors.getAccessor(binding, instance);\r
- testAccessor(accessor);\r
- }\r
- } \r
-\r
- /**\r
- * This test tests composite record by adding 10 fields, and running the \r
- * composition as a record accessor\r
- */\r
- public @Test void testCompositeRecord() throws Exception {\r
- System.out.println("Test composite accessor");\r
- for (int i=0; i<100; i++) {\r
- CompositeRecord record = new CompositeRecord();\r
- for (int j=1; j<=10; j++) {\r
- \r
- Binding binding = Bindings.MUTABLE_VARIANT;\r
- rv = new RandomValue(i*543+j*23); \r
- rv.getRandom().nextLong();\r
- rv.refereableRecords = false; \r
- MutableVariant instance = (MutableVariant) binding.accept(rv);\r
- String fieldName = "Field"+j;\r
- Accessor fa = Accessors.getAccessor(instance.getBinding(), instance.getValue());\r
- record.addField(fieldName, fa);\r
- }\r
- System.out.println(i);\r
- \r
- testAccessor( record );\r
- }\r
- }\r
- \r
- \r
- public @Test void testFolderMap() throws Exception {\r
- // 1000 tests proves failure\r
- for (int i=0; i<100; i++) {\r
- Bindings.defaultBindingRepository.clear();\r
- Bindings.bindingRepository.clear();\r
- Bindings.serializerRepository.clear();\r
- repository.clear();\r
- \r
- System.out.println(i+": ");\r
- File dir = createTmpDir();\r
- DirectoryMap map = Accessors.openDirectory(dir);\r
- Binding keyBinding = Bindings.STR_VARIANT; \r
- try {\r
- System.out.println("Test Folder Map: "+dir); \r
- \r
- // Create 10 files\r
- for (int j=0; j<10; j++) {\r
- rv = new RandomValue(i*231231243+j*213); \r
- rv.refereableRecords = false;\r
- \r
- // Create Key \r
- String key = "";\r
- do {\r
- key = (String) keyBinding.accept(rv);\r
- } while (key.length() > 240);\r
- \r
- // Create value \r
- Datatype valueType = rv.randomType(0, 2); \r
- Binding valueBinding = scheme.getBindingUnchecked(valueType);\r
- Object value = valueBinding.accept(rv); \r
-\r
- System.out.println(key);\r
- MutableVariant vv = new MutableVariant(valueBinding, value);\r
- map.put(Bindings.STR_VARIANT, key, Bindings.MUTABLE_VARIANT, vv);\r
- }\r
- \r
- // Test the map\r
- testAccessor(map);\r
- \r
- } finally {\r
- // Remove all files in the folder\r
- map.clear();\r
- map.close();\r
- System.out.println( dir.listFiles().length + " files.");\r
- dir.delete();\r
- }\r
- \r
- }\r
- \r
- } \r
+
+
+ public @Test void testJavaAccessor() throws Exception {
+ System.out.println("Test Java Objects:");
+ for (int i=0; i<10000; i++) {
+ Bindings.defaultBindingRepository.clear();
+ Bindings.bindingRepository.clear();
+ Bindings.serializerRepository.clear();
+ repository.clear();
+ System.out.println(i+": ");
+ rv = new RandomValue(i);
+ rv.refereableRecords = false;
+ Datatype type = rv.randomType(0, 3);
+ Binding binding = scheme.getBindingUnchecked(type);
+ Object instance = binding.accept(rv);
+// System.out.println(binding.printValue(instance, true));
+ Accessor accessor = Accessors.getAccessor(binding, instance);
+ testAccessor(accessor);
+ }
+ }
+
+ /**
+ * This test tests composite record by adding 10 fields, and running the
+ * composition as a record accessor
+ */
+ public @Test void testCompositeRecord() throws Exception {
+ System.out.println("Test composite accessor");
+ for (int i=0; i<100; i++) {
+ CompositeRecord record = new CompositeRecord();
+ for (int j=1; j<=10; j++) {
+
+ Binding binding = Bindings.MUTABLE_VARIANT;
+ rv = new RandomValue(i*543+j*23);
+ rv.getRandom().nextLong();
+ rv.refereableRecords = false;
+ MutableVariant instance = (MutableVariant) binding.accept(rv);
+ String fieldName = "Field"+j;
+ Accessor fa = Accessors.getAccessor(instance.getBinding(), instance.getValue());
+ record.addField(fieldName, fa);
+ }
+ System.out.println(i);
+
+ testAccessor( record );
+ }
+ }
+
+
+ public @Test void testFolderMap() throws Exception {
+ // 1000 tests proves failure
+ for (int i=0; i<100; i++) {
+ Bindings.defaultBindingRepository.clear();
+ Bindings.bindingRepository.clear();
+ Bindings.serializerRepository.clear();
+ repository.clear();
+
+ System.out.println(i+": ");
+ File dir = createTmpDir();
+ DirectoryMap map = Accessors.openDirectory(dir);
+ Binding keyBinding = Bindings.STR_VARIANT;
+ try {
+ System.out.println("Test Folder Map: "+dir);
+
+ // Create 10 files
+ for (int j=0; j<10; j++) {
+ rv = new RandomValue(i*231231243+j*213);
+ rv.refereableRecords = false;
+
+ // Create Key
+ String key = "";
+ do {
+ key = (String) keyBinding.accept(rv);
+ } while (key.length() > 240);
+
+ // Create value
+ Datatype valueType = rv.randomType(0, 2);
+ Binding valueBinding = scheme.getBindingUnchecked(valueType);
+ Object value = valueBinding.accept(rv);
+
+ System.out.println(key);
+ MutableVariant vv = new MutableVariant(valueBinding, value);
+ map.put(Bindings.STR_VARIANT, key, Bindings.MUTABLE_VARIANT, vv);
+ }
+
+ // Test the map
+ testAccessor(map);
+
+ } finally {
+ // Remove all files in the folder
+ map.clear();
+ map.close();
+ System.out.println( dir.listFiles().length + " files.");
+ dir.delete();
+ }
+
+ }
+
+ }