r131 - in trunk/diswork-fs: . src/test/java/org/nuiton/diswork/fs src/test/java/org/nuiton/diswork/fs/storage
Author: tchemit Date: 2010-10-26 16:21:07 +0200 (Tue, 26 Oct 2010) New Revision: 131 Url: http://nuiton.org/repositories/revision/diswork/131 Log: pass some test to it (there very, but very long :)) Added: trunk/diswork-fs/src/test/java/org/nuiton/diswork/fs/DisworkFileSystemKademliaIT.java trunk/diswork-fs/src/test/java/org/nuiton/diswork/fs/storage/KademliaDisworkMapIT.java Removed: trunk/diswork-fs/src/test/java/org/nuiton/diswork/fs/DisworkFileSystemKademliaTest.java trunk/diswork-fs/src/test/java/org/nuiton/diswork/fs/storage/KademliaDisworkMapTest.java Modified: trunk/diswork-fs/pom.xml Modified: trunk/diswork-fs/pom.xml =================================================================== --- trunk/diswork-fs/pom.xml 2010-10-17 01:39:03 UTC (rev 130) +++ trunk/diswork-fs/pom.xml 2010-10-26 14:21:07 UTC (rev 131) @@ -65,4 +65,36 @@ </plugins> </build> + <profiles> + <profile> + <id>run-its</id> + <activation> + <property> + <name>performRelease</name> + <value>true</value> + </property> + </activation> + <build> + <plugins> + <plugin> + <artifactId>maven-surefire-plugin</artifactId> + <executions> + <execution> + <id>integration-tests</id> + <phase>integration-test</phase> + <goals> + <goal>test</goal> + </goals> + <configuration> + <includes> + <include>**/*IT.java</include> + </includes> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> + </profile> + </profiles> </project> \ No newline at end of file Copied: trunk/diswork-fs/src/test/java/org/nuiton/diswork/fs/DisworkFileSystemKademliaIT.java (from rev 130, trunk/diswork-fs/src/test/java/org/nuiton/diswork/fs/DisworkFileSystemKademliaTest.java) =================================================================== --- trunk/diswork-fs/src/test/java/org/nuiton/diswork/fs/DisworkFileSystemKademliaIT.java (rev 0) +++ trunk/diswork-fs/src/test/java/org/nuiton/diswork/fs/DisworkFileSystemKademliaIT.java 2010-10-26 14:21:07 UTC (rev 131) @@ -0,0 +1,123 @@ +/* + * #%L + * Diswork File-System + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2010 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ +package org.nuiton.diswork.fs; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.FileInputStream; +import java.io.InputStream; +import java.util.ConcurrentModificationException; + +import org.apache.commons.io.IOUtils; +import org.junit.Before; +import org.junit.Test; + +public class DisworkFileSystemKademliaIT extends AbstractDisworkFileSystemTest { + + protected Integer bootstrapPort; + + /** + * this code executed after {@link AbstractDisworkFileSystemTest#setUp()} + * @throws Exception + */ + @Before + public void setUpFileSystem() throws Exception { + // finally, initiate the fileSystem + DisworkFileSystemConfig disworkConfig1 = new DisworkFileSystemConfig(); + disworkConfig1.setMapType("kademlia"); + bootstrapPort = disworkConfig1.getUsedPort(); + fileSystem = new DisworkFileSystem(disworkConfig1); + } + + + @Test + public void testMultipleNodes1() throws Exception { + DisworkFileSystemConfig disworkConfig = new DisworkFileSystemConfig(bootstrapPort); + disworkConfig.setMapType("kademlia"); + DisworkFileSystem fileSystem2 = new DisworkFileSystem(disworkConfig); + + fileSystem.write("/file", new FileInputStream(randomFilePath)); + assertTrue(fileSystem2.exists("/file")); + } + + @Test + public void testMultipleNodes2() throws Exception { + DisworkFileSystemConfig disworkConfig = new DisworkFileSystemConfig(bootstrapPort); + disworkConfig.setMapType("kademlia"); + DisworkFileSystem fileSystem2 = new DisworkFileSystem(disworkConfig); + + InputStream source = null; + try { + source = new FileInputStream(randomFilePath); + fileSystem.write("/my_file", source); + } finally { + IOUtils.closeQuietly(source); + } + + assertTrue(fileSystem.exists("/my_file")); + assertTrue(fileSystem2.exists("/my_file")); + assertEquals(1, fileSystem2.readDirectory("/").size()); + + // now, the checks. We read the original file and the result of + // a read() and then compare it byte-to-byte + + InputStream readResult = null; + try { + source = new FileInputStream(randomFilePath); + readResult = fileSystem2.read("/my_file"); + + assertEquals(randomFileSize, source.available()); + assertEquals(randomFileSize, readResult.available()); + + assertTrue(IOUtils.contentEquals(source, readResult)); + /* + byte[] sourceAsBytes = IOUtils.toByteArray(source); + byte[] readResultAsBytes = IOUtils.toByteArray(readResult); + + assertArrayEquals(sourceAsBytes, readResultAsBytes); + */ + } finally { + IOUtils.closeQuietly(source); + IOUtils.closeQuietly(readResult); + } + + } + + @Test + public void testMultipleNodes3() throws Exception { + DisworkFileSystemConfig disworkConfig = new DisworkFileSystemConfig(bootstrapPort); + disworkConfig.setMapType("kademlia"); + DisworkFileSystem fileSystem2 = new DisworkFileSystem(disworkConfig); + + fileSystem.createDirectory("/mydir"); + try { + fileSystem2.createDirectory("/myseconddir"); + } catch (ConcurrentModificationException e) { + fail(); + } + } +} Deleted: trunk/diswork-fs/src/test/java/org/nuiton/diswork/fs/DisworkFileSystemKademliaTest.java =================================================================== --- trunk/diswork-fs/src/test/java/org/nuiton/diswork/fs/DisworkFileSystemKademliaTest.java 2010-10-17 01:39:03 UTC (rev 130) +++ trunk/diswork-fs/src/test/java/org/nuiton/diswork/fs/DisworkFileSystemKademliaTest.java 2010-10-26 14:21:07 UTC (rev 131) @@ -1,123 +0,0 @@ -/* - * #%L - * Diswork File-System - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ -package org.nuiton.diswork.fs; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.io.FileInputStream; -import java.io.InputStream; -import java.util.ConcurrentModificationException; - -import org.apache.commons.io.IOUtils; -import org.junit.Before; -import org.junit.Test; - -public class DisworkFileSystemKademliaTest extends AbstractDisworkFileSystemTest { - - protected Integer bootstrapPort; - - /** - * this code executed after {@link AbstractDisworkFileSystemTest#setUp()} - * @throws Exception - */ - @Before - public void setUpFileSystem() throws Exception { - // finally, initiate the fileSystem - DisworkFileSystemConfig disworkConfig1 = new DisworkFileSystemConfig(); - disworkConfig1.setMapType("kademlia"); - bootstrapPort = disworkConfig1.getUsedPort(); - fileSystem = new DisworkFileSystem(disworkConfig1); - } - - - @Test - public void testMultipleNodes1() throws Exception { - DisworkFileSystemConfig disworkConfig = new DisworkFileSystemConfig(bootstrapPort); - disworkConfig.setMapType("kademlia"); - DisworkFileSystem fileSystem2 = new DisworkFileSystem(disworkConfig); - - fileSystem.write("/file", new FileInputStream(randomFilePath)); - assertTrue(fileSystem2.exists("/file")); - } - - @Test - public void testMultipleNodes2() throws Exception { - DisworkFileSystemConfig disworkConfig = new DisworkFileSystemConfig(bootstrapPort); - disworkConfig.setMapType("kademlia"); - DisworkFileSystem fileSystem2 = new DisworkFileSystem(disworkConfig); - - InputStream source = null; - try { - source = new FileInputStream(randomFilePath); - fileSystem.write("/my_file", source); - } finally { - IOUtils.closeQuietly(source); - } - - assertTrue(fileSystem.exists("/my_file")); - assertTrue(fileSystem2.exists("/my_file")); - assertEquals(1, fileSystem2.readDirectory("/").size()); - - // now, the checks. We read the original file and the result of - // a read() and then compare it byte-to-byte - - InputStream readResult = null; - try { - source = new FileInputStream(randomFilePath); - readResult = fileSystem2.read("/my_file"); - - assertEquals(randomFileSize, source.available()); - assertEquals(randomFileSize, readResult.available()); - - assertTrue(IOUtils.contentEquals(source, readResult)); - /* - byte[] sourceAsBytes = IOUtils.toByteArray(source); - byte[] readResultAsBytes = IOUtils.toByteArray(readResult); - - assertArrayEquals(sourceAsBytes, readResultAsBytes); - */ - } finally { - IOUtils.closeQuietly(source); - IOUtils.closeQuietly(readResult); - } - - } - - @Test - public void testMultipleNodes3() throws Exception { - DisworkFileSystemConfig disworkConfig = new DisworkFileSystemConfig(bootstrapPort); - disworkConfig.setMapType("kademlia"); - DisworkFileSystem fileSystem2 = new DisworkFileSystem(disworkConfig); - - fileSystem.createDirectory("/mydir"); - try { - fileSystem2.createDirectory("/myseconddir"); - } catch (ConcurrentModificationException e) { - fail(); - } - } -} Copied: trunk/diswork-fs/src/test/java/org/nuiton/diswork/fs/storage/KademliaDisworkMapIT.java (from rev 130, trunk/diswork-fs/src/test/java/org/nuiton/diswork/fs/storage/KademliaDisworkMapTest.java) =================================================================== --- trunk/diswork-fs/src/test/java/org/nuiton/diswork/fs/storage/KademliaDisworkMapIT.java (rev 0) +++ trunk/diswork-fs/src/test/java/org/nuiton/diswork/fs/storage/KademliaDisworkMapIT.java 2010-10-26 14:21:07 UTC (rev 131) @@ -0,0 +1,110 @@ +/* + * #%L + * Diswork File-System + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2010 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ +package org.nuiton.diswork.fs.storage; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.junit.Before; +import org.junit.Test; +import org.nuiton.diswork.fs.DisworkFileSystemConfig; +import org.nuiton.diswork.fs.DisworkFileSystemException; +import org.planx.xmlstore.routing.Identifier; + +public class KademliaDisworkMapIT extends AbstractDisworkMapTest { + + @Before + public void setUp() throws Exception { + DisworkFileSystemConfig config1 = new DisworkFileSystemConfig(); + map1 = new KademliaDisworkMap(config1); + + DisworkFileSystemConfig config2 = new DisworkFileSystemConfig(config1.getUsedPort()); + map2 = new KademliaDisworkMap(config2); + } + + /** + * this tests the key generation algorithm, it has different properties to + * check : + * * two call with same param should return same key + * * two call with different parameter should return different keys + * * a call should never return null + */ + @Test + public void testStringToIdentifier() { + + List<String> paths = new ArrayList<String>(); + + // a set will remove doubloons + Set<Identifier> keys = new HashSet<Identifier>(); + + paths.add("/"); + paths.add("/dir"); + paths.add("/dir/dir"); + paths.add("/a_directory_with_a_long_name_may_lead_to_the_raise_of_an_" + + "exception"); + paths.add("1111111111111111111111111111111111111111111111111111111111"); + paths.add("1111111111111111111111111111111111111111111111111111111112"); + + for (String path : paths) { + Identifier key = KademliaDisworkMap.stringToIdentifier(path); + assertNotNull(key); + + // keys should be equals (depend only from path, not random factor) + Identifier otherKey = KademliaDisworkMap.stringToIdentifier(path); + assertEquals(key, otherKey); + + keys.add(key); + } + + // check differents paths have different keys + // if keys set is too small, there are collisions + assertEquals(paths.size(), keys.size()); + } + + /** + * Tests that an exception is raised when attempting to connect using + * a bad bootstrap + * @throws Exception + */ + @Test + public void testBadBootrap() throws Exception { + DisworkFileSystemConfig config1 = new DisworkFileSystemConfig(); + config1.setBootstrapIp("microsoft.com"); + config1.setBootstrapPort(80); + try { + new KademliaDisworkMap(config1); + fail(); + } catch (DisworkFileSystemException e) { + assertTrue(true); + } + } +} Deleted: trunk/diswork-fs/src/test/java/org/nuiton/diswork/fs/storage/KademliaDisworkMapTest.java =================================================================== --- trunk/diswork-fs/src/test/java/org/nuiton/diswork/fs/storage/KademliaDisworkMapTest.java 2010-10-17 01:39:03 UTC (rev 130) +++ trunk/diswork-fs/src/test/java/org/nuiton/diswork/fs/storage/KademliaDisworkMapTest.java 2010-10-26 14:21:07 UTC (rev 131) @@ -1,110 +0,0 @@ -/* - * #%L - * Diswork File-System - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ -package org.nuiton.diswork.fs.storage; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.junit.Before; -import org.junit.Test; -import org.nuiton.diswork.fs.DisworkFileSystemConfig; -import org.nuiton.diswork.fs.DisworkFileSystemException; -import org.planx.xmlstore.routing.Identifier; - -public class KademliaDisworkMapTest extends AbstractDisworkMapTest { - - @Before - public void setUp() throws Exception { - DisworkFileSystemConfig config1 = new DisworkFileSystemConfig(); - map1 = new KademliaDisworkMap(config1); - - DisworkFileSystemConfig config2 = new DisworkFileSystemConfig(config1.getUsedPort()); - map2 = new KademliaDisworkMap(config2); - } - - /** - * this tests the key generation algorithm, it has different properties to - * check : - * * two call with same param should return same key - * * two call with different parameter should return different keys - * * a call should never return null - */ - @Test - public void testStringToIdentifier() { - - List<String> paths = new ArrayList<String>(); - - // a set will remove doubloons - Set<Identifier> keys = new HashSet<Identifier>(); - - paths.add("/"); - paths.add("/dir"); - paths.add("/dir/dir"); - paths.add("/a_directory_with_a_long_name_may_lead_to_the_raise_of_an_" - + "exception"); - paths.add("1111111111111111111111111111111111111111111111111111111111"); - paths.add("1111111111111111111111111111111111111111111111111111111112"); - - for (String path : paths) { - Identifier key = KademliaDisworkMap.stringToIdentifier(path); - assertNotNull(key); - - // keys should be equals (depend only from path, not random factor) - Identifier otherKey = KademliaDisworkMap.stringToIdentifier(path); - assertEquals(key, otherKey); - - keys.add(key); - } - - // check differents paths have different keys - // if keys set is too small, there are collisions - assertEquals(paths.size(), keys.size()); - } - - /** - * Tests that an exception is raised when attempting to connect using - * a bad bootstrap - * @throws Exception - */ - @Test - public void testBadBootrap() throws Exception { - DisworkFileSystemConfig config1 = new DisworkFileSystemConfig(); - config1.setBootstrapIp("microsoft.com"); - config1.setBootstrapPort(80); - try { - new KademliaDisworkMap(config1); - fail(); - } catch (DisworkFileSystemException e) { - assertTrue(true); - } - } -}
participants (1)
-
tchemit@users.nuiton.org