r81 - in trunk: . mapstoragemanagerarch msm-bighashmap msm-bighashmapV2 msm-bighashmapV2/src msm-bighashmapV2/src/main msm-bighashmapV2/src/main/java msm-bighashmapV2/src/main/java/org msm-bighashmapV2/src/main/java/org/nuiton msm-bighashmapV2/src/main/java/org/nuiton/mapstoragemanager msm-bighashmapV2/src/main/java/org/nuiton/mapstoragemanager/plugins msm-bighashmapV2/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2 msm-bighashmapV2/src/test msm-bighashmapV2/src/t
Author: dlanglais Date: 2010-02-16 13:01:45 +0100 (Tue, 16 Feb 2010) New Revision: 81 Added: trunk/msm-bighashmapV2/ trunk/msm-bighashmapV2/changelog.txt trunk/msm-bighashmapV2/license.txt trunk/msm-bighashmapV2/pom.xml trunk/msm-bighashmapV2/readme.txt trunk/msm-bighashmapV2/src/ trunk/msm-bighashmapV2/src/main/ trunk/msm-bighashmapV2/src/main/java/ trunk/msm-bighashmapV2/src/main/java/org/ trunk/msm-bighashmapV2/src/main/java/org/nuiton/ trunk/msm-bighashmapV2/src/main/java/org/nuiton/mapstoragemanager/ trunk/msm-bighashmapV2/src/main/java/org/nuiton/mapstoragemanager/plugins/ trunk/msm-bighashmapV2/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/ trunk/msm-bighashmapV2/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/BigHashMap.java trunk/msm-bighashmapV2/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/Cell.java trunk/msm-bighashmapV2/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/CellImpl.java trunk/msm-bighashmapV2/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/Column.java trunk/msm-bighashmapV2/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/ColumnImpl.java trunk/msm-bighashmapV2/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/Row.java trunk/msm-bighashmapV2/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/RowImpl.java trunk/msm-bighashmapV2/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/Structure.java trunk/msm-bighashmapV2/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/StructureImpl.java trunk/msm-bighashmapV2/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/Table.java trunk/msm-bighashmapV2/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/TableImpl.java trunk/msm-bighashmapV2/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/package-info.java trunk/msm-bighashmapV2/src/site/ trunk/msm-bighashmapV2/src/test/ trunk/msm-bighashmapV2/src/test/java/ trunk/msm-bighashmapV2/src/test/java/org/ trunk/msm-bighashmapV2/src/test/java/org/nuiton/ trunk/msm-bighashmapV2/src/test/java/org/nuiton/mapstoragemanager/ trunk/msm-bighashmapV2/src/test/java/org/nuiton/mapstoragemanager/plugins/ trunk/msm-bighashmapV2/src/test/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/ trunk/msm-bighashmapV2/src/test/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/CellTest.java trunk/msm-bighashmapV2/src/test/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/ColumnTest.java trunk/msm-bighashmapV2/src/test/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/RowTest.java trunk/msm-bighashmapV2/src/test/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/StructureTest.java trunk/msm-bighashmapV2/src/test/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/TableTest.java Modified: trunk/mapstoragemanagerarch/pom.xml trunk/msm-bighashmap/pom.xml trunk/pom.xml Log: Cr?\195?\169ation d'un nouveau plugin sur la base de MSM-BigHashMap. Ce plugin ne permet de stocker que des Strings, ajouter des objects n'est pas n?\195?\169c?\195?\169ssaire. Les fonctions type hashCode / equals ont ?\195?\169t?\195?\169 retir?\195?\169es car leur utilit?\195?\169 n'est pas justifi?\195?\169e (toujours pour notre programme). Modified: trunk/mapstoragemanagerarch/pom.xml =================================================================== --- trunk/mapstoragemanagerarch/pom.xml 2010-02-16 08:59:24 UTC (rev 80) +++ trunk/mapstoragemanagerarch/pom.xml 2010-02-16 12:01:45 UTC (rev 81) @@ -10,7 +10,7 @@ <url>http://maven.nuiton.org/release</url> </repository> </repositories> - + <modelVersion>4.0.0</modelVersion> <!-- ************************************************************* --> Modified: trunk/msm-bighashmap/pom.xml =================================================================== --- trunk/msm-bighashmap/pom.xml 2010-02-16 08:59:24 UTC (rev 80) +++ trunk/msm-bighashmap/pom.xml 2010-02-16 12:01:45 UTC (rev 81) @@ -71,7 +71,8 @@ <name>MSM-BigHashMap</name> - <description>Creation of a graphic user interface for Hbase </description> + <description>Plugin for MapStorageManager to test with an implementation of + the BigTable Specification using HashMap.</description> <inceptionYear>2010</inceptionYear> <developers> Added: trunk/msm-bighashmapV2/changelog.txt =================================================================== --- trunk/msm-bighashmapV2/changelog.txt (rev 0) +++ trunk/msm-bighashmapV2/changelog.txt 2010-02-16 12:01:45 UTC (rev 81) @@ -0,0 +1,2 @@ +Changelog is not any longer maintained, please refer to the release note : + http://maven-site.nuiton.org/mapstoragemanager/changes-report.html Added: trunk/msm-bighashmapV2/license.txt =================================================================== --- trunk/msm-bighashmapV2/license.txt (rev 0) +++ trunk/msm-bighashmapV2/license.txt 2010-02-16 12:01:45 UTC (rev 81) @@ -0,0 +1,166 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. + Added: trunk/msm-bighashmapV2/pom.xml =================================================================== --- trunk/msm-bighashmapV2/pom.xml (rev 0) +++ trunk/msm-bighashmapV2/pom.xml 2010-02-16 12:01:45 UTC (rev 81) @@ -0,0 +1,266 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + + <!-- repository containing the parent pom. --> + <repositories> + <repository> + <id>org.nuiton</id> + <url>http://maven.nuiton.org/release</url> + </repository> + </repositories> + + <modelVersion>4.0.0</modelVersion> + + <!-- ************************************************************* --> + <!-- *** POM Relationships *************************************** --> + <!-- ************************************************************* --> + <parent> + <groupId>org.nuiton</groupId> + <artifactId>mavenpom4redmine</artifactId> + <version>2.0.4</version> + </parent> + + <version>0.1-SNAPSHOT</version> + <artifactId>msn-bighashmapv2</artifactId> + + <dependencies> + + <dependency> + <groupId>org.nuiton</groupId> + <artifactId>mapstoragemanagerarch</artifactId> + <version>0.1-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.nuiton</groupId> + <artifactId>nuiton-utils</artifactId> + <version>${lutinutil.version}</version> + </dependency> + <dependency> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + <version>1.1.1</version> + </dependency> + + <!--Jaxx--> + <dependency> + <groupId>org.nuiton.jaxx</groupId> + <artifactId>jaxx-runtime</artifactId> + <version>${jaxx.version}</version> + </dependency> + + <dependency> + <groupId>org.nuiton.jaxx</groupId> + <artifactId>jaxx-widgets</artifactId> + <version>${jaxx.version}</version> + </dependency> + <!-- JUnit for tests --> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.7</version> + <scope>test</scope> + </dependency> + </dependencies> + + <!-- ************************************************************* --> + <!-- *** Project Information ************************************* --> + <!-- ************************************************************* --> + + <name>MSM-BigHashMapV2</name> + + <description>Plugin for MapStorageManager to test with an implementation of + the BigTable Specification using HashMap. + This new version fixes some point of MSM-BigHashMap. + For example, previously it was possible to store objects in tables, it is + not useful for MSM ... Now, we store only strings.</description> + <inceptionYear>2010</inceptionYear> + + <developers> + <developer> + <id>tchemit</id> + <name>Tony Chemit</name> + <email>chemit@codelutin.com</email> + <organization>CodeLutin</organization> + <timezone>+2</timezone> + <roles> + <role>Développeur</role> + </roles> + </developer> + <developer> + <id>fdesbois</id> + <name>Florian Desbois</name> + <email>fdesbois@codelutin.com</email> + <organization>CodeLutin</organization> + <timezone>+2</timezone> + <roles> + <role>Développeur</role> + </roles> + </developer> + <developer> + <id>fgilet</id> + <name>Florent Gilet</name> + <email>florent.gilet@etu.univ-nantes.fr</email> + <organization>Université de nantes</organization> + <timezone>+2</timezone> + <roles> + <role>Développeur</role> + </roles> + </developer> + <developer> + <id>gcrieloue</id> + <name>Gilles Crieloue</name> + <email>gilles.crieloue@etu.univ-nantes.fr</email> + <organization>Université de nantes</organization> + <timezone>+2</timezone> + <roles> + <role>Développeur</role> + </roles> + </developer> + <developer> + <id>afages</id> + <name>Amaury Fages</name> + <email>amaury.fages@etu.univ-nantes.fr</email> + <organization>Université de nantes</organization> + <timezone>+2</timezone> + <roles> + <role>Développeur</role> + </roles> + </developer> + <developer> + <id>dlanglais</id> + <name>Dorian langlais</name> + <email>dorain.langlais@etu.univ-nantes.fr</email> + <organization>Université de nantes</organization> + <timezone>+2</timezone> + <roles> + <role>Développeur</role> + </roles> + </developer> + </developers> + + <!-- ************************************************************* --> + <!-- *** Build Settings ****************************************** --> + <!-- ************************************************************* --> + <packaging>jar</packaging> + + <properties> + + <!-- main class in jar + <maven.jar.main.class>org.nuiton.mapstoragemanager.Main</maven.jar.main.class>--> + <jaxx.version>2.0.0-beta-3</jaxx.version> + <lutinutil.version>1.1.2</lutinutil.version> + <i18n.version>1.0.1</i18n.version> + + <!-- jaxx + <jaxx.useUIManagerForIcon>true</jaxx.useUIManagerForIcon> + <jaxx.addProjectClassPath>true</jaxx.addProjectClassPath> + <jaxx.addSourcesToClassPath>true</jaxx.addSourcesToClassPath>--> + </properties> + + <build> + + <plugins> + + <!--<plugin> + <groupId>org.nuiton.jaxx</groupId> + <artifactId>maven-jaxx-plugin</artifactId> + <version>${jaxx.version}</version> + <executions> + <execution> + <goals> + <goal>generate</goal> + </goals> + </execution> + </executions> + </plugin> + + <plugin> + <groupId>org.nuiton.i18n</groupId> + <artifactId>maven-i18n-plugin</artifactId> + <version>${i18n.version}</version> + <configuration> + silent>true</silent + <entries> + <entry> + <basedir>${maven.gen.dir}/java/</basedir> + </entry> + </entries> + </configuration> + <executions> + <execution> + <goals> + <goal>parserJava</goal> + <goal>bundle</goal> + </goals> + </execution> + </executions> + </plugin>--> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-dependency-plugin</artifactId> + <executions> + <execution> + <id>copy-deps</id> + <goals> + <goal>copy-dependencies</goal> + </goals> + <configuration> + <silent>true</silent> + <overWriteReleases>false</overWriteReleases> + <overWriteSnapshots>false</overWriteSnapshots> + <overWriteIfNewer>true</overWriteIfNewer> + <outputDirectory>${project.build.directory}/lib</outputDirectory> + </configuration> + </execution> + </executions> + + </plugin> + + </plugins> + + <pluginManagement> + <plugins> + + <plugin> + <groupId>org.nuiton</groupId> + <artifactId>maven-license-plugin</artifactId> + <configuration> + <copyToMETA_INF>true</copyToMETA_INF> + </configuration> + </plugin> + + <plugin> + <artifactId>maven-jar-plugin</artifactId> + <configuration> + <archive> + <manifest> + <addClasspath>true</addClasspath> + <classpathPrefix>./lib/</classpathPrefix> + </manifest> + </archive> + </configuration> + </plugin> + + <!-- plugin site --> + <!--<plugin> + <artifactId>maven-site-plugin</artifactId> + <dependencies> + <dependency> + <groupId>org.nuiton</groupId> + <artifactId>doxia-module-jrst</artifactId> + <version>${jrst.version}</version> + </dependency> + </dependencies> + </plugin>--> + + </plugins> + </pluginManagement> + </build> + +</project> + + Added: trunk/msm-bighashmapV2/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/BigHashMap.java =================================================================== --- trunk/msm-bighashmapV2/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/BigHashMap.java (rev 0) +++ trunk/msm-bighashmapV2/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/BigHashMap.java 2010-02-16 12:01:45 UTC (rev 81) @@ -0,0 +1,141 @@ +package org.nuiton.mapstoragemanager.plugins.bighashmapv2; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import org.nuiton.mapstoragemanager.plugins.NewBigTable; + +/** + * Interface listant les méthodes nécéssaires sur une base de données. + * @author Dorian Langlais + * + */ +public class BigHashMap implements NewBigTable { + + /** + * tables. + * hashMap with value is table, and key its name. + */ + private Map<String, Table> tables; + /** + * currentTable. + * the table which is selected. + */ + // Not used + //private Table currentTable; + + /** + * Default constructor. + */ + public BigHashMap() { + this.tables = new HashMap<String, Table>(); + // Not used + //currentTable = null; + } + + /** + * {@inheritDoc} + * Create a new HashMap database. + */ + public boolean connect(String host, int port, String base, String username, String passwd) { + //throw new UnsupportedOperationException("Not supported yet."); + new BigHashMap(); + return true; + } + + /** + * {@inheritDoc} + */ + public void selectTable(String table) { + // Not used + //this.currentTable = tables.get(table); + } + + /** + * {@inheritDoc} + */ + public void createTable(String table) { + this.tables.put(table, new TableImpl()); + } + + /** + * {@inheritDoc} + */ + public void deleteTable(String table) { + this.tables.remove(table); + } + + /** + * {@inheritDoc} + */ + public Set<String> getTablesNames() { + return this.tables.keySet(); + } + + /** + * {@inheritDoc} + */ + public void createColumn(String table, String column) { + this.tables.get(table).createColumn(column); + } + + /** + * {@inheritDoc} + */ + public void deleteColumn(String table, String column) { + this.tables.get(table).deleteColumn(column); + } + + /** + * {@inheritDoc} + */ + public Set<String> getColumnsNames(String table) { + return this.tables.get(table).getColumnsNames(); + } + + /** + * {@inheritDoc} + */ + public void put(String table, String column, String key, String content) { + this.tables.get(table).put(column, key, content); + } + + /** + * {@inheritDoc} + */ + public String get(String table, String column, String key) { + return this.tables.get(table).get(column, key).toString(); + } + + /** + * {@inheritDoc} + */ + public String get(String table, String column, String key, int version) { + return this.tables.get(table).get(column, key, version).toString(); + } + + /** + * {@inheritDoc} + */ + public Map<String, String> getRow(String table, String key) { + + Row row = this.tables.get(table).getRow(key); + + Map<String,String> rowContent = row.getRowContent(); + Map<String,String> rowMap = new HashMap<String,String>(); + + for(String rowKey : rowContent.keySet()) { + String rowValue = rowContent.get(rowKey).toString(); + rowMap.put(rowKey, rowValue); + } + return rowMap; + } + + /** + * {@inheritDoc} + */ + public Set<String> getKeys(String table) { + return this.tables.get(table).getKeys(); + } + +} Added: trunk/msm-bighashmapV2/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/Cell.java =================================================================== --- trunk/msm-bighashmapV2/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/Cell.java (rev 0) +++ trunk/msm-bighashmapV2/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/Cell.java 2010-02-16 12:01:45 UTC (rev 81) @@ -0,0 +1,45 @@ +package org.nuiton.mapstoragemanager.plugins.bighashmapv2; + +/** + * Interface to present the method an a Cell. + * @author Dorian Langlais + */ +public interface Cell { + + /** + * Get the most recent object put in the cell. + * @return The most recent object stored in the cell. + */ + String get(); + + /** + * Put a new object in the cell. + * @param t Objet to store in the cell. + */ + void put(String t); + + /** + * Get an object from its "version". + * The version number start at 0, and increase one by one at each new + * version. + * @param t the version wanted (it can be timestamp, number..). + * @return The object corresponding to the "version". + */ + String get(Long t); + +// /** +// * hashCode(). +// * @return +// */ +// int hashCode(); +// +// /** +// * equals(). +// */ +// boolean equals(Object o); + + /** + * toString(). + */ + String toString(); +} Added: trunk/msm-bighashmapV2/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/CellImpl.java =================================================================== --- trunk/msm-bighashmapV2/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/CellImpl.java (rev 0) +++ trunk/msm-bighashmapV2/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/CellImpl.java 2010-02-16 12:01:45 UTC (rev 81) @@ -0,0 +1,113 @@ +package org.nuiton.mapstoragemanager.plugins.bighashmapv2; + +import java.util.HashMap; +import java.util.Map; +import java.util.NoSuchElementException; + +/** + * Class Cell. + * A cell contain different version of a content. + * So a cell store String and its version. + * @author dorian Langlais, amaury Fages, gilles Crieloue, florent Gilet. + * @licence GPL. + */ +public class CellImpl implements Cell { + + /** + * cell. + * hashMap with key as timestamp and value, as object of T class. + */ + private Map<Long, String> cell; + + /** + * Default constructor. + */ + public CellImpl() { + this.cell = new HashMap<Long, String>(); + } + + /** + * Constructor with object. + * @param t The object to store. + */ + public CellImpl(String t) { + this.cell = new HashMap<Long, String>(); + this.put(t); + } + + /** + * {@inheritDoc} + */ + public final void put(final String t) { + cell.put((long)cell.size(), t); + //cell.put(System.currentTimeMillis(), t); + } + + /** + * {@inheritDoc} + */ + public final String get(final Long timestamp) { + return cell.get(timestamp); + } + + /** + * {@inheritDoc} + */ + public final String get() { + if (this.cell.isEmpty()) { + throw new NoSuchElementException(); + } + Long max = 0L; + for (Long current : cell.keySet()) { + if (max < current) { + max = current; + } + } + return cell.get(max); + } + +// /** +// * {@inheritDoc} +// */ +// public int hashCode() { +// if (! this.cell.isEmpty()) { +// return this.get().hashCode(); +// } else { +// return 0; +// } +// } +// +// /** +// * {@inheritDoc} +// * //TODO : we consider only the last item... but it will be better to +// * //TODO verify all the "versions" of the cell. +// */ +// public boolean equals(Object o) { +// if (o instanceof CellImpl) { +// CellImpl another = (CellImpl) o; +// if(this.cell.size() == another.cell.size()) { +// if(this.cell.isEmpty()) { +// return true; +// } else { +// return this.get().equals(another.get()); +// } +// } else { +// return false; +// } +// } else { +// return false; +// } +// } + + /** + * {@inheritDoc} + */ + public String toString() { + + if (! this.cell.isEmpty()) { + return ((String) this.get()).toString(); + } else { + return ""; + } + } +} Added: trunk/msm-bighashmapV2/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/Column.java =================================================================== --- trunk/msm-bighashmapV2/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/Column.java (rev 0) +++ trunk/msm-bighashmapV2/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/Column.java 2010-02-16 12:01:45 UTC (rev 81) @@ -0,0 +1,60 @@ +package org.nuiton.mapstoragemanager.plugins.bighashmapv2; + +import java.util.Set; + +/** + * Interface to present the method to implement for en Column. + * @author Dorian Langlais + */ +public interface Column { + + /** + * Get the object which has key <b>key</key>. + * @param key the key. + * @return the object stored at the line identified by <b>key</b> + */ + String get(String key); + + /** + * Get the object which has key <b>key</key> and version <b>version</b>. + * @param key + * @param version the version wanted (it can be timestamp, number..). + * @return The object corresponding to the "version". + */ + String get(String key, Long version); + + /** + * Put object <b>t</b> with the key <b>key</b>. + * @param key the key + * @param t object to store + */ + void put(String key, String t); + + /** + * Delete an object by its key. + * @param key the key + */ + void delete(String key); + +// /** +// * hashCode(). +// * @return +// */ +// int hashCode(); +// +// /** +// * equals(). +// */ +// boolean equals(Object o); + + /** + * toString(). + */ + String toString(); + + /** + * Get the keys of the column. + * @return return a Set containing all the keys of the column. + */ + Set<String> getKeys(); +} Added: trunk/msm-bighashmapV2/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/ColumnImpl.java =================================================================== --- trunk/msm-bighashmapV2/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/ColumnImpl.java (rev 0) +++ trunk/msm-bighashmapV2/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/ColumnImpl.java 2010-02-16 12:01:45 UTC (rev 81) @@ -0,0 +1,108 @@ +package org.nuiton.mapstoragemanager.plugins.bighashmapv2; + +import java.util.HashMap; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Set; + +/** + * Classe Column. + * @author dorian Langlais, amaury Fages, gilles Crieloue, florent Gilet. + * @licence GPL. + */ +public class ColumnImpl implements Column { + + /** + * column. + * hashMap with key the key of the line, and value a column. + */ + private Map<String, CellImpl> column; + + /** + * Default constructor. + */ + public ColumnImpl() { + column = new HashMap<String, CellImpl>(); + } + + /** + * {@inheritDoc} + */ + public final String get(final String key, final Long timestamp) { + return this.column.get(key).get(timestamp); + } + + /** + * {@inheritDoc} + */ + public final String get(final String key) { + if (this.column.get(key) == null) { + throw new NoSuchElementException(); + } + return this.column.get(key).get(); + } + + /** + * {@inheritDoc} + */ + public final void put(final String key, final String content) { + if(this.column.keySet().contains(key)) { + this.column.get(key).put(content); + } else { + this.column.put(key, new CellImpl(content)); + } + } + + /** + * {@inheritDoc} + */ + public final void delete(final String key) { + this.column.remove(key); + } + +// /** +// * {@inheritDoc} +// */ +// public final int hashCode() { +// int hash = 0; +// for(Cell c : column.values()) { +// hash += c.hashCode(); +// } +// return hash; +// } +// +// /** +// * {@inheritDoc} +// */ +// public boolean equals(Object o) { +// if (o instanceof Column) { +// +// ColumnImpl other = (ColumnImpl) o; +// +// return other.column.equals(this.column); +// +// } else { +// return false; +// } +// } + + /** + * {@inheritDoc} + */ + public final String toString() { + String ret = ""; + + for (String key : column.keySet()) { + ret += key + "\t" + column.get(key); + } + + return ret; + } + + /** + * {@inheritDoc} + */ + public Set<String> getKeys() { + return this.column.keySet(); + } +} Added: trunk/msm-bighashmapV2/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/Row.java =================================================================== --- trunk/msm-bighashmapV2/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/Row.java (rev 0) +++ trunk/msm-bighashmapV2/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/Row.java 2010-02-16 12:01:45 UTC (rev 81) @@ -0,0 +1,36 @@ +package org.nuiton.mapstoragemanager.plugins.bighashmapv2; + +import java.util.Map; + +/** + * Interface to present the methods on a Row + * @author Dorian Langlais + * + */ +public interface Row { + + /** + * to string a row. + * @return the row in textual format. + */ + String toString(); + + /** + * Get row structure. + * @return the row structure + */ + Structure getRowStructure(); + + /** + * Get row content. + * @return the row content + */ + Map<String, String> getRowContent(); + + /** + * Get an element of the row. + * @param columnName the column name. + * @return the content of the "cell". + */ + String getContent(String columnName); +} Added: trunk/msm-bighashmapV2/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/RowImpl.java =================================================================== --- trunk/msm-bighashmapV2/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/RowImpl.java (rev 0) +++ trunk/msm-bighashmapV2/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/RowImpl.java 2010-02-16 12:01:45 UTC (rev 81) @@ -0,0 +1,65 @@ +package org.nuiton.mapstoragemanager.plugins.bighashmapv2; + +import java.util.HashMap; +import java.util.Map; + +/** + * Class RowImpl. + * A row of a table. + * @author Dorian Langlais. + */ +public class RowImpl implements Row { + + /** + * Structure of the row. + */ + private Structure rowStructure; + /** + * Content of the row. + */ + private Map<String, String> rowContent; + + /** + * Row constructor. + * @param struct the row structure + * @param content the row content + */ + public RowImpl(final Structure struct, + final Map<String, String> content) { + this.rowStructure = struct; + this.rowContent = new HashMap<String, String>(); + for (String columnName : struct.getColumnsNames()) { + rowContent.put(columnName, content.get(columnName)); + } + } + + /** + * {@inheritDoc} + */ + public Structure getRowStructure() { + return rowStructure; + } + + /** + * {@inheritDoc} + */ + public Map<String, String> getRowContent() { + return rowContent; + } + + /** + * {@inheritDoc} + */ + public final String toString() { + String ret; + ret = rowContent.values().toString(); + return ret; + } + + /** + * {@inheritDoc} + */ + public String getContent(String columnName) { + return rowContent.get(columnName); + } +} Added: trunk/msm-bighashmapV2/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/Structure.java =================================================================== --- trunk/msm-bighashmapV2/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/Structure.java (rev 0) +++ trunk/msm-bighashmapV2/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/Structure.java 2010-02-16 12:01:45 UTC (rev 81) @@ -0,0 +1,49 @@ +package org.nuiton.mapstoragemanager.plugins.bighashmapv2; + +import java.util.Set; + +/** + * Interface to present the method on a structure. + * A structure is a description of a table. + * @author Dorian Langlais + * + */ +public interface Structure { + + /** + * Add a new column in the structure. + * @param columnName the column name + */ + void createColumn(String columnName); + + /** + * Get the columns' names. + * @return return a set containing the name of the columns. + */ + Set<String> getColumnsNames(); + + /** + * Remove a column of the structure by its name. + * @param columnName the column name + */ + void deleteColumn(String columnName); + +// /** +// * get the hashCode of the structure. +// * @return return the hashCode of the structure. +// */ +// int hashCode(); +// +// /** +// * Permit to verify if this is equals to another object. +// * @param another the object to compare +// * @return true if this is equals to <b>another</b> +// */ +// boolean equals(Object o); + + /** + * toString(). + * @return + */ + String toString(); +} Added: trunk/msm-bighashmapV2/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/StructureImpl.java =================================================================== --- trunk/msm-bighashmapV2/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/StructureImpl.java (rev 0) +++ trunk/msm-bighashmapV2/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/StructureImpl.java 2010-02-16 12:01:45 UTC (rev 81) @@ -0,0 +1,90 @@ +package org.nuiton.mapstoragemanager.plugins.bighashmapv2; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +/** + * Class Structure. + * Represente the mapping between a row and the column of a table. + * @author Dorian Langlais + * + */ +public class StructureImpl implements Structure { + + /** + * structure. + * hashMap with key the column name, and value the column class. + */ + private Set<String> structure; + + /** + * Default constructor. + */ + public StructureImpl() { + this.structure = + new HashSet<String>(); + } + + /** + * {@inheritDoc} + */ + public final void createColumn(final String columnName) { + this.structure.add(columnName); + } + + /** + * {@inheritDoc} + */ + public final void deleteColumn(final String columnName) { + this.structure.remove(columnName); + } + + /** + * {@inheritDoc} + */ + public final Set<String> getColumnsNames() { + return this.structure; + } + +// /** +// * {@inheritDoc} +// */ +// public final int hashCode() { +// if (structure.isEmpty()) { +// return 0; +// } else { +// int hash = 0; +// for (String key : structure) { +// hash += key.hashCode(); +// } +// return hash; +// } +// } +// +// /** +// * {@inheritDoc} +// */ +// public final boolean equals(Object o) { +// if (o instanceof StructureImpl) { +// StructureImpl another = (StructureImpl) o; +// +// return this.structure.equals(another.structure); +// +// } else { +// return false; +// } +// } + + /** + * {@inheritDoc} + */ + public final String toString() { + String ret = ""; + for (String key : this.structure) { + ret += key + "\t"; + } + return ret; + } +} Added: trunk/msm-bighashmapV2/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/Table.java =================================================================== --- trunk/msm-bighashmapV2/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/Table.java (rev 0) +++ trunk/msm-bighashmapV2/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/Table.java 2010-02-16 12:01:45 UTC (rev 81) @@ -0,0 +1,80 @@ +package org.nuiton.mapstoragemanager.plugins.bighashmapv2; + +import java.util.Set; + +/** + * Interface to present the method on a table. + * A table is like a table in SGBD, but in BigTable, the data are stored in + * columns not in rows. + * @author Dorian Langlais + */ +public interface Table { + + /** + * Create a column in the table. + * @param columnName the column name + * @param <columnClass> generics to spécify the class of the stored objects. + */ + <columnClass> void createColumn(final String columnName); + + /** + * Delete a colum of the table. + * @param columnName the column name. + */ + void deleteColumn(final String columnName); + + /** + * Get the columns' name of the table. + * @return Return a set containing the columns' name of the table + */ + Set<String> getColumnsNames(); + + /** + * Get a "virtual" rom from the table. + * @param key the key of the row to get + * @return return the row which has <b>key</b> as key + */ + Row getRow(final String key); + + /** + * Remove a row by its key. + * @param key the key + */ + void deleteRow(final String key); + + /** + * Put an object in the table. + * Put the objct <b>o</b> in the column <b>columnName</b> at the key + * <b>key</b>. + * @param columnName the columnName + * @param key the key + * @param content the content + */ + void put(final String columnName, final String key, final String content); + + /** + * Get an object from the table. + * Get an object from the column <b>columnName</b> with the key <b>key</b>. + * @param columnName the columnName + * @param key the key + * @return return the object stored + */ + Object get(final String columnName, final String key); + + /** + * Get an object from the table. + * Get an object from the column <b>columnName</b> with the key <b>key</b> + * and the versiion number <b>version</b>. + * @param columnName the columnName + * @param key the key + * @param version the version wanted + * @return return the object stored + */ + Object get(final String columnName, final String key, final long version); + + /** + * Get the keys of the table. + * @return return a set which contains all the keys of the table. + */ + Set<String> getKeys(); +} Added: trunk/msm-bighashmapV2/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/TableImpl.java =================================================================== --- trunk/msm-bighashmapV2/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/TableImpl.java (rev 0) +++ trunk/msm-bighashmapV2/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/TableImpl.java 2010-02-16 12:01:45 UTC (rev 81) @@ -0,0 +1,109 @@ +package org.nuiton.mapstoragemanager.plugins.bighashmapv2; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +/** + * Class Table. + * Implements the interface Table. + * @author dorian Langlais, amaury Fages, gilles Crieloue, florent Gilet. + * @licence GPL. + */ +public class TableImpl implements Table { + + /** + * Table. + * hashMap with key as column name and value, a colum of the table. + */ + private Map<String, Column> tableColumns; + /** + * Structure of the table. + */ + private StructureImpl tableStructure; + + /** + * Default constructor. + */ + public TableImpl() { + this.tableColumns = new HashMap<String, Column>(); + this.tableStructure = new StructureImpl(); + } + + /** + * {@inheritDoc} + */ + public final <columnClass> void createColumn(final String columnName) { + Column column = new ColumnImpl(); + this.tableColumns.put(columnName, column); + this.tableStructure.createColumn(columnName); + } + + /** + * {@inheritDoc} + */ + public final void deleteColumn(final String columnName) { + this.tableColumns.remove(columnName); + this.tableStructure.deleteColumn(columnName); + } + + /** + * {@inheritDoc} + */ + public final Row getRow(final String key) { + Map<String, String> rowContent = new HashMap<String, String>(); + for (String columnName : tableStructure.getColumnsNames()) { + rowContent.put(columnName, tableColumns.get(columnName).get(key)); + } + return new RowImpl(tableStructure, rowContent); + } + + /** + * {@inheritDoc} + */ + public void deleteRow(final String key) { + for (Column column : tableColumns.values()) { + column.delete(key); + } + } + + /** + * {@inheritDoc} + */ + public void put(String columnName, String key, String content) { + this.tableColumns.get(columnName).put(key, content); + } + + /** + * {@inheritDoc} + */ + public Object get(String columnName, String key) { + return this.tableColumns.get(columnName).get(key); + } + + /** + * {@inheritDoc} + */ + public Object get(String columnName, String key, long version) { + return this.tableColumns.get(columnName).get(key, version); + } + + /** + * {@inheritDoc} + */ + public Set<String> getColumnsNames() { + return this.tableColumns.keySet(); + } + + /** + * {@inheritDoc} + */ + public Set<String> getKeys() { + Set<String> keys = new HashSet<String>(); + for(Column col : this.tableColumns.values()){ + keys.addAll(col.getKeys()); + } + return keys; + } +} Added: trunk/msm-bighashmapV2/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/package-info.java =================================================================== --- trunk/msm-bighashmapV2/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/package-info.java (rev 0) +++ trunk/msm-bighashmapV2/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/package-info.java 2010-02-16 12:01:45 UTC (rev 81) @@ -0,0 +1,6 @@ +package org.nuiton.mapstoragemanager.plugins.bighashmapv2; +/** + * package BigHashMap. + * permet la représentation sous forme de hashMap d'une base de données selon + * la spécification bigTable. + */ Added: trunk/msm-bighashmapV2/src/test/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/CellTest.java =================================================================== --- trunk/msm-bighashmapV2/src/test/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/CellTest.java (rev 0) +++ trunk/msm-bighashmapV2/src/test/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/CellTest.java 2010-02-16 12:01:45 UTC (rev 81) @@ -0,0 +1,187 @@ +package org.nuiton.mapstoragemanager.plugins.bighashmapv2; + +import org.nuiton.mapstoragemanager.plugins.bighashmapv2.CellImpl; +import org.nuiton.mapstoragemanager.plugins.bighashmapv2.Cell; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.util.NoSuchElementException; + +import junit.framework.Assert; +import junit.framework.TestCase; + +/** + * Classe de test pour la classe Cell. + * Teste les fonctions de base d'une cellule, put et get. + * @author Dorian Langlais + * + */ +public final class CellTest extends TestCase { + + /** + * Logger. + */ + private static final Log log = LogFactory.getLog(CellTest.class); + + private Cell cellActual; + private Cell cell2Actual; + private String objectExpected1; + private String objectExpected2; + private String objectExpected3; + + /** + * On teste le comportement de get avec une cellule vide. + */ + public void testGetVoid() { + cellActual = new CellImpl(); + try { + assertNull(cellActual.get()); + Assert.fail(); + } catch (NoSuchElementException e) { + log.info("Exception levée correctement"); + } + } + + /** + * Test de la fonction put sur une cellule. + * On ajoute un objet obj1, on tente de le récupérer. + */ + public void testPut() { + + cellActual = new CellImpl(); + + objectExpected1 = new String("objectExpected1"); + + try { + assertNull(cellActual.get()); + Assert.fail(); + } catch (NoSuchElementException e) { + log.info("Exception levée correctement"); + } + cellActual.put(objectExpected1); + + assertEquals(cellActual.get(), objectExpected1); + } + + /** + * Test de la fonction put sur une cellule. + * On ajoute un objet obj1, on tente de le récupérer. + * On ajoute un objet obj2, on tente de le récupérer. + * On ajoute un objet obj3, on tente de le récupérer. + */ + public void testPutReput() { + + cellActual = new CellImpl(); + + objectExpected1 = new String("objectExpected1"); + + try { + assertNull(cellActual.get()); + Assert.fail(); + } catch (NoSuchElementException e) { + log.info("Exception levée correctement"); + } + cellActual.put(objectExpected1); + + assertEquals(cellActual.get(), objectExpected1); + + objectExpected2 = new String("objectExpected2"); + + cellActual.put(objectExpected2); + + assertEquals(cellActual.get(), objectExpected2); + + objectExpected3 = new String("objectExpected3"); + + cellActual.put(objectExpected3); + + assertEquals(cellActual.get(), objectExpected3); + } + +// /** +// * We make two cells with the same objects, and we verify that they are +// * equals. +// */ +// public void testEquals() { +// +// /** +// * We create two cells. +// */ +// cellActual = new CellImpl(); +// cell2Actual = new CellImpl(); +// assertEquals(cellActual, cell2Actual); +// +// objectExpected1 = new String("objectExpected1"); +// +// /** +// * We put one item in the first Cell, and not in the second. +// */ +// cellActual.put(objectExpected1); +// assertNotSame(cellActual, cell2Actual); +// +// /** +// * We put the same object in the second cell. +// */ +// cell2Actual.put(objectExpected1); +// assertEquals(cellActual, cell2Actual); +// } +// +// /** +// * We make two cells with the same objects, and we verify that thay have +// * the same hashCode. +// */ +// public void testHashCode() { +// +// /** +// * We create two cells. +// */ +// cellActual = new CellImpl(); +// cell2Actual = new CellImpl(); +// assertEquals(cellActual.hashCode(), cell2Actual.hashCode()); +// +// objectExpected1 = new String("objectExpected1"); +// +// /** +// * We put one item in the first Cell, and not in the second. +// */ +// cellActual.put(objectExpected1); +// assertNotSame(cellActual.hashCode(), cell2Actual.hashCode()); +// +// /** +// * We put the same object in the second cell. +// */ +// cell2Actual.put(objectExpected1); +// assertEquals(cellActual.hashCode(), cell2Actual.hashCode()); +// } + + /** + * we test that toString do what we want. + */ + public void testToString() { + + /** + * We create one cell and werify that toString equals "" when the cell + * is empty. + */ + cellActual = new CellImpl(); + assertEquals(cellActual.toString(), ""); + + /** + * We create and put one object Integer(1337) and control that + * toString() equals "1337" + */ + objectExpected1 = new String("1337"); + cellActual.put(objectExpected1); + assertEquals(cellActual.toString(), objectExpected1.toString()); + assertEquals(cellActual.toString(), "1337"); + + /** + * We create and put another object String("String for testing") and + * control that toString() equals "String for testing". + */ + objectExpected1 = new String("String for testing"); + cellActual.put(objectExpected1); + assertEquals(cellActual.toString(), objectExpected1.toString()); + assertEquals(cellActual.toString(), "String for testing"); + } +} Added: trunk/msm-bighashmapV2/src/test/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/ColumnTest.java =================================================================== --- trunk/msm-bighashmapV2/src/test/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/ColumnTest.java (rev 0) +++ trunk/msm-bighashmapV2/src/test/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/ColumnTest.java 2010-02-16 12:01:45 UTC (rev 81) @@ -0,0 +1,270 @@ +package org.nuiton.mapstoragemanager.plugins.bighashmapv2; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Set; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import junit.framework.Assert; +import junit.framework.TestCase; + +public final class ColumnTest extends TestCase { + + /** + * Logger. + */ + private static final Log log = LogFactory.getLog(ColumnTest.class); + + private Column columnActual1; + private Column columnActual2; + private String expected1; + private String expected2; + + /** + * We test column when empty. + */ + public void testGetVoid() { + columnActual1 = new ColumnImpl(); + try { + columnActual1.get("test"); + Assert.fail(); + } catch (NoSuchElementException e) { + log.info("Exception levée correctement"); + } + } + + /** + * We put one object and we try to get it. + */ + public void testPutAndGet() { + columnActual1 = new ColumnImpl(); + + expected1 = new String("expected"); + + try { + columnActual1.get("object 1"); + Assert.fail(); + } catch (NoSuchElementException e) { + log.info("Exception levée correctement"); + } + + columnActual1.put("object 1", expected1); + + assertEquals(columnActual1.get("object 1"), expected1); + + } + + /** + * We put two object, we verify that they are in the column. + * Then, we try to remove them. + */ + public void testDelete() { + columnActual1 = new ColumnImpl(); + + expected1 = new String("1"); + expected2 = new String("2"); + + columnActual1.put("integer 1", expected1); + columnActual1.put("integer 2", expected2); + + assertEquals(columnActual1.get("integer 1"), expected1); + assertEquals(columnActual1.get("integer 2"), expected2); + + /** + * Now we try to remove integer 1. + */ + columnActual1.delete("integer 1"); + try{ + columnActual1.get("integer 1"); + Assert.fail(); + } catch (NoSuchElementException e) { + log.info("Exception levée correctement."); + } + assertEquals(columnActual1.get("integer 2"), expected2); + + /** + * Finally, we try to remove integer 2. + */ + columnActual1.delete("integer 2"); + try{ + columnActual1.get("integer 2"); + Assert.fail(); + } catch (NoSuchElementException e) { + log.info("Exception levée correctement."); + } + } + +// /** +// * testhashCode(). +// */ +// public void testHashCode() { +// +// int hashCodeSum = 0; +// String toStore; +// +// /** +// * We create a new column and verify that hashCode is 0. +// */ +// columnActual1 = new ColumnImpl(); +// assertEquals(columnActual1.hashCode(), 0); +// +// /** +// * We put a Integer(10) and control that hashCode is already ok. +// */ +// toStore = new String("10"); +// columnActual1.put("key1", toStore); +// hashCodeSum += toStore.hashCode(); +// assertEquals(columnActual1.hashCode(), hashCodeSum); +// +// toStore = new String("peanuts"); +// columnActual1.put("key2", toStore); +// hashCodeSum += toStore.hashCode(); +// assertEquals(columnActual1.hashCode(), hashCodeSum); +// } +// +// /** +// * testEquals(). +// */ +// public void testEquals() { +// +// /** +// * We create two columns. +// */ +// columnActual1 = new ColumnImpl(); +// columnActual2 = new ColumnImpl(); +// assertEquals(columnActual1, columnActual2); +// +// /** +// * We put one object in the first column, and not in the second. +// */ +// expected1 = new String("10"); +// columnActual1.put("key1",expected1); +// assertNotSame(columnActual1, columnActual2); +// +// /** +// * We put the same object in the second column at the same key. +// */ +// columnActual2.put("key1",expected1); +// assertEquals(columnActual1, columnActual2); +// +// /** +// * We put the same object in the two column but at a different key. +// */ +// expected2 = new String("Tomatoes"); +// columnActual1.put("key2",expected2); +// columnActual2.put("key3",expected2); +// assertNotSame(columnActual1, columnActual2); +// } + + /** + * We test the method toString() on Column. + */ + public void testToString() { + + String toStore, toStore2; + Map<String,Object> columnContent; + String toStringExpected; + /** + * We create one columns. + */ + columnActual1 = new ColumnImpl(); + columnContent = new HashMap<String, Object>(); + toStringExpected = new String(); + for (String key : columnContent.keySet()) { + toStringExpected += key + "\t" + columnContent.get(key).toString(); + } + assertEquals(columnActual1.toString(), toStringExpected); + + /** + * We put one object in the column. + */ + toStore = new String("10"); + columnActual1.put("key1", toStore); + columnContent.put("key1", toStore); + toStringExpected = new String(); + for (String key : columnContent.keySet()) { + toStringExpected += key + "\t" + columnContent.get(key).toString(); + } + assertEquals(columnActual1.toString(), toStringExpected); + + /** + * We put another object in the column. + */ + toStore2 = new String("yahoo !"); + columnActual1.put("key2", toStore2); + columnContent.put("key2", toStore2); + toStringExpected = new String(); + for (String key : columnContent.keySet()) { + toStringExpected += key + "\t" + columnContent.get(key).toString(); + } + assertEquals(columnActual1.toString(), toStringExpected); + } + + /** + * We put objects in the columns and we get the keys. + * We compare with the key set attempt. + */ + public void testGetKeys(){ + + columnActual1 = new ColumnImpl(); + + Set<String> expectedSet = new HashSet<String>(); + + /** + * We put object, we and verify that the keySet returned is good. + */ + columnActual1.put("obj1", new String()); + expectedSet.add("obj1"); + assertEquals(expectedSet, columnActual1.getKeys()); + + columnActual1.put("obj2", new String()); + expectedSet.add("obj2"); + assertEquals(expectedSet, columnActual1.getKeys()); + + columnActual1.put("obj3", new String()); + expectedSet.add("obj3"); + assertEquals(expectedSet, columnActual1.getKeys()); + + columnActual1.put("obj4", new String()); + expectedSet.add("obj4"); + assertEquals(expectedSet, columnActual1.getKeys()); + + columnActual1.put("obj5", new String()); + expectedSet.add("obj5"); + assertEquals(expectedSet, columnActual1.getKeys()); + + /** + * We try to add already exist key. + */ + columnActual1.put("obj5", new String()); + expectedSet.add("obj5"); + assertEquals(expectedSet, columnActual1.getKeys()); + + /** + * Now, we will remove object by their keys, and we verify the keySet. + */ + columnActual1.delete("obj1"); + expectedSet.remove("obj1"); + assertEquals(expectedSet, columnActual1.getKeys()); + + columnActual1.delete("obj3"); + expectedSet.remove("obj3"); + assertEquals(expectedSet, columnActual1.getKeys()); + + columnActual1.delete("obj5"); + expectedSet.remove("obj5"); + assertEquals(expectedSet, columnActual1.getKeys()); + + /** + * We try to remove no exist keys : + */ + columnActual1.delete("obj6"); + expectedSet.remove("obj6"); + assertEquals(expectedSet, columnActual1.getKeys()); + + } +} Added: trunk/msm-bighashmapV2/src/test/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/RowTest.java =================================================================== --- trunk/msm-bighashmapV2/src/test/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/RowTest.java (rev 0) +++ trunk/msm-bighashmapV2/src/test/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/RowTest.java 2010-02-16 12:01:45 UTC (rev 81) @@ -0,0 +1,161 @@ +package org.nuiton.mapstoragemanager.plugins.bighashmapv2; + +import org.nuiton.mapstoragemanager.plugins.bighashmapv2.StructureImpl; +import org.nuiton.mapstoragemanager.plugins.bighashmapv2.Row; +import org.nuiton.mapstoragemanager.plugins.bighashmapv2.RowImpl; +import org.nuiton.mapstoragemanager.plugins.bighashmapv2.Structure; +import java.util.HashMap; +import java.util.Map; +import junit.framework.TestCase; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +public class RowTest extends TestCase { + + /** + * Logger. + */ + private static final Log log = LogFactory.getLog(RowTest.class); + + private Structure structureExpected; + private Map<String, String> contentExpected; + private Row rowActual; + + public void testToString() { + { + structureExpected = new StructureImpl(); + contentExpected = new HashMap<String, String>(); + rowActual = new RowImpl(structureExpected, contentExpected); + + assertEquals(rowActual.toString(), contentExpected.values().toString()); + } + + { + structureExpected = new StructureImpl(); + structureExpected.createColumn("Test"); + contentExpected = new HashMap<String, String>(); + contentExpected.put("Test", "StringDeTest"); + rowActual = new RowImpl(structureExpected, contentExpected); + + assertEquals(rowActual.toString(), contentExpected.values().toString()); + } + + { + structureExpected = new StructureImpl(); + structureExpected.createColumn("Test1"); + structureExpected.createColumn("Test2"); + structureExpected.createColumn("Test3"); + contentExpected = new HashMap<String, String>(); + contentExpected.put("Test1", "StringDeTest"); + contentExpected.put("Test2", "1"); + contentExpected.put("Test3", "0.07"); + rowActual = new RowImpl(structureExpected, contentExpected); + + assertEquals(rowActual.toString(), contentExpected.values().toString()); + } + } + + public void testGetRowContent() { + { + structureExpected = new StructureImpl(); + contentExpected = new HashMap<String, String>(); + rowActual = new RowImpl(structureExpected, contentExpected); + + assertEquals(rowActual.getRowContent(), contentExpected); + } + + { + structureExpected = new StructureImpl(); + structureExpected.createColumn("Test"); + contentExpected = new HashMap<String, String>(); + contentExpected.put("Test", "StringDeTest"); + rowActual = new RowImpl(structureExpected, contentExpected); + + assertEquals(rowActual.getRowContent(), contentExpected); + } + + { + structureExpected = new StructureImpl(); + structureExpected.createColumn("Test1"); + structureExpected.createColumn("Test2"); + structureExpected.createColumn("Test3"); + contentExpected = new HashMap<String, String>(); + contentExpected.put("Test1", "StringDeTest"); + contentExpected.put("Test2", "1"); + contentExpected.put("Test3", "0.07"); + rowActual = new RowImpl(structureExpected, contentExpected); + + assertEquals(rowActual.getRowContent(), contentExpected); + } + } + + public void testGetRowStructure() { + { + structureExpected = new StructureImpl(); + contentExpected = new HashMap<String, String>(); + rowActual = new RowImpl(structureExpected, contentExpected); + + assertEquals(rowActual.getRowStructure(), structureExpected); + } + + { + structureExpected = new StructureImpl(); + structureExpected.createColumn("Test"); + contentExpected = new HashMap<String, String>(); + contentExpected.put("Test", "StringDeTest"); + rowActual = new RowImpl(structureExpected, contentExpected); + + assertEquals(rowActual.getRowStructure(), structureExpected); + } + + { + structureExpected = new StructureImpl(); + structureExpected.createColumn("Test1"); + structureExpected.createColumn("Test2"); + structureExpected.createColumn("Test3"); + contentExpected = new HashMap<String, String>(); + contentExpected.put("Test1", "StringDeTest"); + contentExpected.put("Test2", "1"); + contentExpected.put("Test3", "0.07"); + rowActual = new RowImpl(structureExpected, contentExpected); + + assertEquals(rowActual.getRowStructure(), structureExpected); + } + } + + public void testGetContent() { + { + structureExpected = new StructureImpl(); + contentExpected = new HashMap<String, String>(); + rowActual = new RowImpl(structureExpected, contentExpected); + + assertEquals(rowActual.getContent(""), null); + } + + { + structureExpected = new StructureImpl(); + structureExpected.createColumn("Test"); + contentExpected = new HashMap<String, String>(); + contentExpected.put("Test", "StringDeTest"); + rowActual = new RowImpl(structureExpected, contentExpected); + + assertEquals(rowActual.getContent("Test"), "StringDeTest"); + } + + { + structureExpected = new StructureImpl(); + structureExpected.createColumn("Test1"); + structureExpected.createColumn("Test2"); + structureExpected.createColumn("Test3"); + contentExpected = new HashMap<String, String>(); + contentExpected.put("Test1", "StringDeTest"); + contentExpected.put("Test2", "1"); + contentExpected.put("Test3", "0.07"); + rowActual = new RowImpl(structureExpected, contentExpected); + + assertEquals(rowActual.getContent("Test1"), "StringDeTest"); + assertEquals(rowActual.getContent("Test2"), "1"); + assertEquals(rowActual.getContent("Test3"), "0.07"); + } + } +} Added: trunk/msm-bighashmapV2/src/test/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/StructureTest.java =================================================================== --- trunk/msm-bighashmapV2/src/test/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/StructureTest.java (rev 0) +++ trunk/msm-bighashmapV2/src/test/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/StructureTest.java 2010-02-16 12:01:45 UTC (rev 81) @@ -0,0 +1,231 @@ +package org.nuiton.mapstoragemanager.plugins.bighashmapv2; + +import org.nuiton.mapstoragemanager.plugins.bighashmapv2.StructureImpl; +import org.nuiton.mapstoragemanager.plugins.bighashmapv2.Structure; +import java.lang.reflect.Field; +import java.util.HashSet; +import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; + +import junit.framework.TestCase; +import org.apache.commons.logging.LogFactory; +import org.apache.commons.logging.Log; + +public class StructureTest extends TestCase { + + /** + * Logger. + */ + private static final Log log = LogFactory.getLog(StructureTest.class); + + private Structure structureActual; + private Set<String> structureContentActual; + private Set<String> structureContentExpected; + private Class<?> columnsClassActual; + private Class<?> columnsClassExpected; + private Set<String> columnsNamesActual; + private Set<String> columnsNamesExpected; + + public void testGetColumnsNamesVoid() { + structureActual = new StructureImpl(); + Set<String> columnNames = structureActual.getColumnsNames(); + assertEquals(0, columnNames.size()); + } + + /** + * we add a column with name and class. + * We use reflexivity to verify that the map of the structure is like we + * want. + */ + public void testAddColumn() { + + structureContentExpected = new HashSet<String>(); + + try { + structureActual = new StructureImpl(); + + Field fStructure = structureActual.getClass().getDeclaredField("structure"); + fStructure.setAccessible(true); + Set<String> structureContentActual = + (Set<String>) fStructure.get(structureActual); + + + structureActual.createColumn("Test1"); + structureContentExpected.add("Test1"); + assertEquals(structureContentExpected, structureContentActual); + + structureActual.createColumn("Test2"); + structureContentExpected.add("Test2"); + assertEquals(structureContentExpected, structureContentActual); + + structureActual.createColumn("Test3"); + structureContentExpected.add("Test3"); + assertEquals(structureContentExpected, structureContentActual); + + } catch (IllegalArgumentException ex) { + Logger.getLogger(StructureTest.class.getName()).log(Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + Logger.getLogger(StructureTest.class.getName()).log(Level.SEVERE, null, ex); + } catch (NoSuchFieldException ex) { + Logger.getLogger(StructureTest.class.getName()).log(Level.SEVERE, null, ex); + } catch (SecurityException ex) { + Logger.getLogger(StructureTest.class.getName()).log(Level.SEVERE, null, ex); + } + } + + /** + * we add a column with name and class. + * We use reflexivity to verify that the map of the structure is like we + * want. + * We remove column, and we continue to verify that the map of the structure + * is always good. + */ + public void testRemoveColumn() { + + structureContentExpected = new HashSet<String>(); + + try { + structureActual = new StructureImpl(); + + Field fStructure = structureActual.getClass().getDeclaredField("structure"); + fStructure.setAccessible(true); + Set<String> structureContentActual = + (Set<String>) fStructure.get(structureActual); + + + structureActual.createColumn("Test1"); + structureContentExpected.add("Test1"); + structureActual.createColumn("Test2"); + structureContentExpected.add("Test2"); + structureActual.createColumn("Test3"); + structureContentExpected.add("Test3"); + assertEquals(structureContentExpected, structureContentActual); + + structureActual.deleteColumn("Test1"); + structureContentExpected.remove("Test1"); + assertEquals(structureContentExpected, structureContentActual); + + /** + * the key "Test1TOTO" is not in the structure. + */ + structureActual.deleteColumn("Test1TOTO"); + structureContentExpected.remove("Test1TOTO"); + assertEquals(structureContentExpected, structureContentActual); + + structureActual.deleteColumn("Test2"); + structureContentExpected.remove("Test2"); + assertEquals(structureContentExpected, structureContentActual); + + structureActual.deleteColumn("Test3"); + structureContentExpected.remove("Test3"); + assertEquals(structureContentExpected, structureContentActual); + + /** + * We try to remove an other key, but the map is empty. + */ + structureActual.deleteColumn("Test4"); + structureContentExpected.remove("Test4"); + + assertEquals(structureContentExpected, structureContentActual); + + + } catch (IllegalArgumentException ex) { + Logger.getLogger(StructureTest.class.getName()).log(Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + Logger.getLogger(StructureTest.class.getName()).log(Level.SEVERE, null, ex); + } catch (NoSuchFieldException ex) { + Logger.getLogger(StructureTest.class.getName()).log(Level.SEVERE, null, ex); + } catch (SecurityException ex) { + Logger.getLogger(StructureTest.class.getName()).log(Level.SEVERE, null, ex); + } + } + + /** + * we add a column with name and class. + * We use reflexivity to verify that the columsNames returned are goods. + * We remove column, and we continue to verify that the columsNames is + * always good. + */ + public void testGetColumnsNames() { + + structureActual = new StructureImpl(); + + columnsNamesExpected = new HashSet<String>(); + columnsNamesActual = structureActual.getColumnsNames(); + + + structureActual.createColumn("Test1"); + columnsNamesExpected.add("Test1"); + assertEquals(columnsNamesExpected, columnsNamesActual); + + structureActual.createColumn("Test2"); + columnsNamesExpected.add("Test2"); + assertEquals(columnsNamesExpected, columnsNamesActual); + + structureActual.createColumn("Test3"); + columnsNamesExpected.add("Test3"); + assertEquals(columnsNamesExpected, columnsNamesActual); + + structureActual.deleteColumn("Test1"); + columnsNamesExpected.remove("Test1"); + assertEquals(columnsNamesExpected, columnsNamesActual); + + /** + * the key "Test1TOTO" is not in the structure. + */ + structureActual.deleteColumn("Test1TOTO"); + columnsNamesExpected.remove("Test1TOTO"); + assertEquals(columnsNamesExpected, columnsNamesActual); + + structureActual.deleteColumn("Test2"); + columnsNamesExpected.remove("Test2"); + assertEquals(columnsNamesExpected, columnsNamesActual); + + structureActual.deleteColumn("Test3"); + columnsNamesExpected.remove("Test3"); + assertEquals(columnsNamesExpected, columnsNamesActual); + + /** + * We try to remove an other key, but the map is empty. + */ + structureActual.deleteColumn("Test4"); + columnsNamesExpected.remove("Test4"); + + assertEquals(columnsNamesExpected, columnsNamesActual); + + } + +// /** +// * we create and delete columns. +// * we calculate hashcode and compare to hashCode(). +// */ +// public void testHashCode() { +// +// structureActual = new StructureImpl(); +// int hashCodeExpected = 0; +// assertEquals(structureActual.hashCode(), hashCodeExpected); +// +// /** +// * We create column "Test1" +// */ +// structureActual.createColumn("Test1"); +// hashCodeExpected += "Test1".hashCode(); +// assertEquals(structureActual.hashCode(), hashCodeExpected); +// +// /** +// * We create column "Test2" +// */ +// structureActual.createColumn("Test2"); +// hashCodeExpected += "Test2".hashCode(); +// assertEquals(structureActual.hashCode(), hashCodeExpected); +// +// /** +// * We delete column "Test1" +// */ +// structureActual.deleteColumn("Test1"); +// hashCodeExpected -= "Test1".hashCode(); +// assertEquals(structureActual.hashCode(), hashCodeExpected); +// +// } +} Added: trunk/msm-bighashmapV2/src/test/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/TableTest.java =================================================================== --- trunk/msm-bighashmapV2/src/test/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/TableTest.java (rev 0) +++ trunk/msm-bighashmapV2/src/test/java/org/nuiton/mapstoragemanager/plugins/bighashmapv2/TableTest.java 2010-02-16 12:01:45 UTC (rev 81) @@ -0,0 +1,515 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package org.nuiton.mapstoragemanager.plugins.bighashmapv2; + +import java.lang.reflect.Field; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; +import junit.framework.Assert; +import junit.framework.TestCase; +import org.apache.commons.logging.LogFactory; +import org.apache.commons.logging.Log; + +/** + * + * @author Dorian Langlais + */ +public class TableTest extends TestCase { + + /** + * Logger. + */ + private static final Log log = LogFactory.getLog(TableTest.class); + + private Table tableActual; + private Structure tableStructureActual; + private HashMap<String, Column> tableColumnsActual; + private Structure tableStructureExpected; + private HashMap<String, Column> tableColumnsExpected; + + /** + * We create a new table and we verify that the fields are correctly + * initialized. + */ + public void testNewTable() { + + tableActual = new TableImpl(); + + tableStructureExpected = new StructureImpl(); + tableColumnsExpected = new HashMap<String, Column>(); + + try { + Field fTableStructure = + tableActual.getClass().getDeclaredField("tableStructure"); + Field fTablecolumns = + tableActual.getClass().getDeclaredField("tableColumns"); + fTableStructure.setAccessible(true); + fTablecolumns.setAccessible(true); + tableStructureActual = (Structure) fTableStructure.get(tableActual); + tableColumnsActual = (HashMap<String, Column>) fTablecolumns.get(tableActual); + + assertEquals(tableStructureActual.toString(), + tableStructureExpected.toString()); + assertEquals(tableColumnsActual.toString(), + tableColumnsExpected.toString()); + + } catch (IllegalArgumentException ex) { + Logger.getLogger(TableTest.class.getName()).log(Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + Logger.getLogger(TableTest.class.getName()).log(Level.SEVERE, null, ex); + } catch (NoSuchFieldException ex) { + Logger.getLogger(TableTest.class.getName()).log(Level.SEVERE, null, ex); + } catch (SecurityException ex) { + Logger.getLogger(TableTest.class.getName()).log(Level.SEVERE, null, ex); + } + + } + + /** + * We create columns and we verify that they are actually in the table and + * in the structure of the table. + */ + public void testCreateColumn() { + + tableActual = new TableImpl(); + + tableStructureExpected = new StructureImpl(); + tableColumnsExpected = new HashMap<String, Column>(); + + try { + Field fTableStructure = + tableActual.getClass().getDeclaredField("tableStructure"); + Field fTablecolumns = + tableActual.getClass().getDeclaredField("tableColumns"); + fTableStructure.setAccessible(true); + fTablecolumns.setAccessible(true); + tableStructureActual = (Structure) fTableStructure.get(tableActual); + tableColumnsActual = (HashMap<String, Column>) fTablecolumns.get(tableActual); + + /** + * We add one column. + */ + tableActual.createColumn("Test1"); + tableStructureExpected.createColumn("Test1"); + tableColumnsExpected.put("Test1", new ColumnImpl()); + + assertEquals(tableStructureActual.toString(), + tableStructureExpected.toString()); + assertEquals(tableColumnsActual.toString(), + tableColumnsExpected.toString()); + + /** + * We add another column. + */ + tableActual.createColumn("Test2"); + tableStructureExpected.createColumn("Test2"); + tableColumnsExpected.put("Test2", new ColumnImpl()); + + assertEquals(tableStructureActual.toString(), + tableStructureExpected.toString()); + assertEquals(tableColumnsActual.toString(), + tableColumnsExpected.toString()); + + /** + * add an already existing column has no effect. + */ + tableActual.createColumn("Test1"); + + assertEquals(tableStructureActual.toString(), + tableStructureExpected.toString()); + assertEquals(tableColumnsActual.toString(), + tableColumnsExpected.toString()); + + } catch (IllegalArgumentException ex) { + Logger.getLogger(TableTest.class.getName()).log(Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + Logger.getLogger(TableTest.class.getName()).log(Level.SEVERE, null, ex); + } catch (NoSuchFieldException ex) { + Logger.getLogger(TableTest.class.getName()).log(Level.SEVERE, null, ex); + } catch (SecurityException ex) { + Logger.getLogger(TableTest.class.getName()).log(Level.SEVERE, null, ex); + } + + } + + /** + * We create some columns and remove them. + * After add them, we verify that the are actually in the table and in the + * structure. + * The we remove them one by one, and we verify that they are really removed + * of the table and of the structure. + */ + public void testRemoveColumn() { + + tableActual = new TableImpl(); + + tableStructureExpected = new StructureImpl(); + tableColumnsExpected = new HashMap<String, Column>(); + + try { + Field fTableStructure = + tableActual.getClass().getDeclaredField("tableStructure"); + Field fTablecolumns = + tableActual.getClass().getDeclaredField("tableColumns"); + fTableStructure.setAccessible(true); + fTablecolumns.setAccessible(true); + tableStructureActual = (Structure) fTableStructure.get(tableActual); + tableColumnsActual = (HashMap<String, Column>) fTablecolumns.get(tableActual); + + /** + * We add two columns. + */ + tableActual.createColumn("Test1"); + tableStructureExpected.createColumn("Test1"); + tableColumnsExpected.put("Test1", new ColumnImpl()); + tableActual.createColumn("Test2"); + tableStructureExpected.createColumn("Test2"); + tableColumnsExpected.put("Test2", new ColumnImpl()); + + assertEquals(tableStructureActual.toString(), + tableStructureExpected.toString()); + assertEquals(tableColumnsActual.toString(), + tableColumnsExpected.toString()); + + /** + * We try to remove a column. + */ + tableActual.deleteColumn("Test1"); + tableStructureExpected.deleteColumn("Test1"); + tableColumnsExpected.remove("Test1"); + + assertEquals(tableStructureActual.toString(), + tableStructureExpected.toString()); + assertEquals(tableColumnsActual.toString(), + tableColumnsExpected.toString()); + + /** + * We try to remove another column. + */ + tableActual.deleteColumn("Test2"); + tableStructureExpected.deleteColumn("Test2"); + tableColumnsExpected.remove("Test2"); + + assertEquals(tableStructureActual.toString(), + tableStructureExpected.toString()); + assertEquals(tableColumnsActual.toString(), + tableColumnsExpected.toString()); + + + } catch (IllegalArgumentException ex) { + Logger.getLogger(TableTest.class.getName()).log(Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + Logger.getLogger(TableTest.class.getName()).log(Level.SEVERE, null, ex); + } catch (NoSuchFieldException ex) { + Logger.getLogger(TableTest.class.getName()).log(Level.SEVERE, null, ex); + } catch (SecurityException ex) { + Logger.getLogger(TableTest.class.getName()).log(Level.SEVERE, null, ex); + } + + } + + /** + * We create a new Table, with two columns. + * We put objects in this columns and we use reflexivity to verify that + * objects are really stored in the table. + */ + public void testPut() { + + /** + * We create object to put + */ + String expectedString1 = new String("string1"); + String expectedString2 = new String("string2"); + String expectedInteger1 = new String("1"); + String expectedInteger2 = new String("2"); + /** + * We create the table and columns. + */ + tableActual = new TableImpl(); + tableActual.createColumn("String"); + tableActual.createColumn("Integer"); + /** + * We put objects in the table. + */ + tableActual.put("String", "string1", expectedString1); + tableActual.put("String", "string2", expectedString2); + tableActual.put("Integer", "integer1", expectedInteger1); + tableActual.put("Integer", "integer2", expectedInteger2); + + try { + /** + * We use reflexivity to verify that objects are really stored. + */ + Field fTableColumns = tableActual.getClass().getDeclaredField("tableColumns"); + fTableColumns.setAccessible(true); + Map<String, Column> tableColumns = (Map<String, Column>) fTableColumns.get(tableActual); + + assertEquals(expectedString1, tableColumns.get("String").get("string1")); + assertEquals(expectedString2, tableColumns.get("String").get("string2")); + assertEquals(expectedInteger1, tableColumns.get("Integer").get("integer1")); + assertEquals(expectedInteger2, tableColumns.get("Integer").get("integer2")); + + } catch (NoSuchFieldException ex) { + Logger.getLogger(TableTest.class.getName()).log(Level.SEVERE, null, ex); + } catch (SecurityException ex) { + Logger.getLogger(TableTest.class.getName()).log(Level.SEVERE, null, ex); + } catch (IllegalArgumentException ex) { + Logger.getLogger(TableTest.class.getName()).log(Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + Logger.getLogger(TableTest.class.getName()).log(Level.SEVERE, null, ex); + } + } + + /** + * We create a new Table, with two columns. + * We put objects in this columns and we try to get them. + */ + public void testGet() { + + /** + * We create object to put (and get) + */ + String expectedString1 = new String("string1"); + String expectedString2 = new String("string2"); + String expectedInteger1 = new String("1"); + String expectedInteger2 = new String("2"); + + /** + * We create the table and columns. + */ + tableActual = new TableImpl(); + tableActual.createColumn("String"); + tableActual.createColumn("Integer"); + + /** + * We put objects in the table. + */ + tableActual.put("String", "string1", expectedString1); + tableActual.put("String", "string2", expectedString2); + tableActual.put("Integer", "integer1", expectedInteger1); + tableActual.put("Integer", "integer2", expectedInteger2); + + /** + * We try to get them. + */ + assertEquals(expectedString1, tableActual.get("String", "string1")); + assertEquals(expectedString2, tableActual.get("String", "string2")); + assertEquals(expectedInteger1, tableActual.get("Integer", "integer1")); + assertEquals(expectedInteger2, tableActual.get("Integer", "integer2")); + } + + /** + * We create a new Table, with two columns. + * We put objects in this columns and we try to get it. + */ + public void testPutAndGetWithVersion() { + + /** + * We create object to put (and get). + */ + String expectedString1 = new String("string1"); + String expectedString2 = new String("string2"); + String expectedInteger1 = new String("1"); + String expectedInteger2 = new String("2"); + + /** + * We create the table and columns. + */ + tableActual = new TableImpl(); + tableActual.createColumn("String"); + tableActual.createColumn("Integer"); + + /** + * We put objects in the table. + */ + tableActual.put("String", "string1", expectedString1); + tableActual.put("String", "string2", expectedString2); + tableActual.put("Integer", "integer1", expectedInteger1); + tableActual.put("Integer", "integer2", expectedInteger2); + + /** + * We try to get them. + */ + assertEquals(expectedString1, tableActual.get("String", "string1")); + assertEquals(expectedString2, tableActual.get("String", "string2")); + assertEquals(expectedInteger1, tableActual.get("Integer", "integer1")); + assertEquals(expectedInteger2, tableActual.get("Integer", "integer2")); + + /** + * We try to get them with their version number. + */ + assertEquals(expectedString1, tableActual.get("String", "string1",0)); + assertEquals(expectedString2, tableActual.get("String", "string2",0)); + assertEquals(expectedInteger1, tableActual.get("Integer", "integer1",0)); + assertEquals(expectedInteger2, tableActual.get("Integer", "integer2",0)); + + /** + * We create new object to store in the table. + */ + String expectedString1v2 = new String("string1v2"); + String expectedString2v2 = new String("string2v2"); + String expectedInteger1v2 = new String("12"); + String expectedInteger2v2 = new String("22"); + + /** + * We put them in the table. + */ + tableActual.put("String", "string1", expectedString1v2); + tableActual.put("String", "string2", expectedString2v2); + tableActual.put("Integer", "integer1", expectedInteger1v2); + tableActual.put("Integer", "integer2", expectedInteger2v2); + + /** + * We try to get them by get() : normally we get the last version. + */ + assertEquals(expectedString1v2, tableActual.get("String", "string1")); + assertEquals(expectedString2v2, tableActual.get("String", "string2")); + assertEquals(expectedInteger1v2, tableActual.get("Integer", "integer1")); + assertEquals(expectedInteger2v2, tableActual.get("Integer", "integer2")); + + /** + * We try get the the first version. + */ + assertEquals(expectedString1, tableActual.get("String", "string1",0)); + assertEquals(expectedString2, tableActual.get("String", "string2",0)); + assertEquals(expectedInteger1, tableActual.get("Integer", "integer1",0)); + assertEquals(expectedInteger2, tableActual.get("Integer", "integer2",0)); + + /** + * We try to get the actual version by its version number. + */ + assertEquals(expectedString1v2, tableActual.get("String", "string1",1)); + assertEquals(expectedString2v2, tableActual.get("String", "string2",1)); + assertEquals(expectedInteger1v2, tableActual.get("Integer", "integer1",1)); + assertEquals(expectedInteger2v2, tableActual.get("Integer", "integer2",1)); + + } + + /** + * We pu object in the table and we verify that the ketset return is good. + */ + public void testGetKeys() { + + Set<String> keySet = new HashSet<String>(); + + /** + * We create object to put. + */ + String expectedString1 = new String("string1"); + String expectedString2 = new String("string2"); + String expectedInteger1 = new String("1"); + String expectedInteger2 = new String("2"); + + /** + * We create the table and columns. + */ + tableActual = new TableImpl(); + tableActual.createColumn("String"); + tableActual.createColumn("Integer"); + + /** + * We put objects in the table and their keys in the keySet. + */ + tableActual.put("String", "string1", expectedString1); + keySet.add("string1"); + assertEquals(keySet, tableActual.getKeys()); + + tableActual.put("String", "string2", expectedString2); + keySet.add("string2"); + assertEquals(keySet, tableActual.getKeys()); + + tableActual.put("Integer", "integer1", expectedInteger1); + keySet.add("integer1"); + assertEquals(keySet, tableActual.getKeys()); + + tableActual.put("Integer", "integer2", expectedInteger2); + keySet.add("integer2"); + assertEquals(keySet, tableActual.getKeys()); + } + + /** + * We create a new Table, with two columns. + * We put objects in this columns and we try to remove them. + */ + public void testDelete() { + + /** + * We create object to put (and get) + */ + String expectedString1 = new String("string1"); + String expectedString2 = new String("string2"); + String expectedInteger1 = new String("1"); + String expectedInteger2 = new String("2"); + + /** + * We create the table and columns. + */ + tableActual = new TableImpl(); + tableActual.createColumn("String"); + tableActual.createColumn("Integer"); + + /** + * We put objects in the table. + */ + tableActual.put("String", "string1", expectedString1); + tableActual.put("String", "string2", expectedString2); + tableActual.put("Integer", "integer1", expectedInteger1); + tableActual.put("Integer", "integer2", expectedInteger2); + + /** + * We try to get them. + */ + assertEquals(expectedString1, tableActual.get("String", "string1")); + assertEquals(expectedString2, tableActual.get("String", "string2")); + assertEquals(expectedInteger1, tableActual.get("Integer", "integer1")); + assertEquals(expectedInteger2, tableActual.get("Integer", "integer2")); + + /** + * Now, we will try to delete them. + */ + tableActual.deleteRow("string1"); + try{ + tableActual.get("String", "string1"); + Assert.fail(); + } catch (NoSuchElementException e) { + log.info("Exception levée correctement."); + } + assertEquals(expectedString2, tableActual.get("String", "string2")); + assertEquals(expectedInteger1, tableActual.get("Integer", "integer1")); + assertEquals(expectedInteger2, tableActual.get("Integer", "integer2")); + + tableActual.deleteRow("string2"); + try{ + tableActual.get("String", "string2"); + Assert.fail(); + } catch (NoSuchElementException e) { + log.info("Exception levée correctement."); + } + assertEquals(expectedInteger1, tableActual.get("Integer", "integer1")); + assertEquals(expectedInteger2, tableActual.get("Integer", "integer2")); + + tableActual.deleteRow("integer1"); + try{ + tableActual.get("Integer", "integer1"); + Assert.fail(); + } catch (NoSuchElementException e) { + log.info("Exception levée correctement."); + } + assertEquals(expectedInteger2, tableActual.get("Integer", "integer2")); + + tableActual.deleteRow("integer2"); + try{ + tableActual.get("Integer", "integer2"); + Assert.fail(); + } catch (NoSuchElementException e) { + log.info("Exception levée correctement."); + } + } +} Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2010-02-16 08:59:24 UTC (rev 80) +++ trunk/pom.xml 2010-02-16 12:01:45 UTC (rev 81) @@ -28,6 +28,7 @@ <modules> <module>mapstoragemanagerarch</module> <module>msm-bighashmap</module> + <module>msm-bighashmapV2</module> <module>msm-hbase</module> </modules>
participants (1)
-
dlanglais@users.nuiton.org