Author: bloritsch Date: Mon Dec 6 10:03:19 2004 New Revision: 109997 URL: http://svn.apache.org/viewcvs?view=rev&rev=109997 Log: Add some more meat to the ConnectSource implementation and fix some testing issues Added: incubator/directory/seda/branches/berin_api_proposal/SedaRedesign.iml incubator/directory/seda/branches/berin_api_proposal/SedaRedesign.ipr Modified: incubator/directory/seda/branches/berin_api_proposal/ (props changed) incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/input/ConnectSource.java incubator/directory/seda/branches/berin_api_proposal/src/test/org/apache/directory/seda/input/test/TestConnectSource.java
Added: incubator/directory/seda/branches/berin_api_proposal/SedaRedesign.iml Url: http://svn.apache.org/viewcvs/incubator/directory/seda/branches/berin_api_proposal/SedaRedesign.iml?view=auto&rev=109997 ============================================================================== --- (empty file) +++ incubator/directory/seda/branches/berin_api_proposal/SedaRedesign.iml Mon Dec 6 10:03:19 2004 @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="UTF-8"?> +<module version="4" relativePaths="true" type="JAVA_MODULE"> + <component name="ModuleRootManager" /> + <component name="NewModuleRootManager"> + <output url="file://$MODULE_DIR$/target/classes" /> + <exclude-output /> + <exclude-exploded /> + <output-test url="file://$MODULE_DIR$/target/test-classes" /> + <content url="file://$MODULE_DIR$"> + <sourceFolder url="file://$MODULE_DIR$/src/java" isTestSource="false" /> + <sourceFolder url="file://$MODULE_DIR$/src/test" isTestSource="true" /> + <excludeFolder url="file://$MODULE_DIR$/.clover" /> + </content> + <orderEntry type="inheritedJdk" /> + <orderEntry type="sourceFolder" forTests="false" /> + <orderEntry type="library" name="Clover" level="application" /> + <orderEntry type="library" name="Doug Lea's Concurrent" level="application" /> + <orderEntry type="library" name="JUnit" level="application" /> + <orderEntry type="library" name="Event" level="application" /> + <orderEntryProperties /> + </component> +</module> + Added: incubator/directory/seda/branches/berin_api_proposal/SedaRedesign.ipr Url: http://svn.apache.org/viewcvs/incubator/directory/seda/branches/berin_api_proposal/SedaRedesign.ipr?view=auto&rev=109997 ============================================================================== --- (empty file) +++ incubator/directory/seda/branches/berin_api_proposal/SedaRedesign.ipr Mon Dec 6 10:03:19 2004 @@ -0,0 +1,231 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4" relativePaths="false"> + <component name="AntConfiguration"> + <defaultAnt bundledAnt="true" /> + </component> + <component name="CodeStyleSettingsManager"> + <option name="PER_PROJECT_SETTINGS" /> + <option name="USE_PER_PROJECT_SETTINGS" value="false" /> + </component> + <component name="CompilerConfiguration"> + <option name="DEFAULT_COMPILER" value="Javac" /> + <option name="CLEAR_OUTPUT_DIRECTORY" value="false" /> + <option name="DEPLOY_AFTER_MAKE" value="0" /> + <resourceExtensions> + <entry name=".+\.(properties|xml|html|dtd|tld)" /> + <entry name=".+\.(gif|png|jpeg|jpg)" /> + </resourceExtensions> + <wildcardResourcePatterns> + <entry name="?*.properties" /> + <entry name="?*.xml" /> + <entry name="?*.html" /> + <entry name="?*.dtd" /> + <entry name="?*.tld" /> + <entry name="?*.gif" /> + <entry name="?*.png" /> + <entry name="?*.jpeg" /> + <entry name="?*.jpg" /> + </wildcardResourcePatterns> + </component> + <component name="DataSourceManagerImpl" /> + <component name="DependencyValidationManager" /> + <component name="EntryPointsManager"> + <entry_points /> + </component> + <component name="ExportToHTMLSettings"> + <option name="PRINT_LINE_NUMBERS" value="false" /> + <option name="OPEN_IN_BROWSER" value="false" /> + <option name="OUTPUT_DIRECTORY" /> + </component> + <component name="GUI Designer component loader factory" /> + <component name="JavacSettings"> + <option name="DEBUGGING_INFO" value="true" /> + <option name="GENERATE_NO_WARNINGS" value="false" /> + <option name="DEPRECATION" value="true" /> + <option name="ADDITIONAL_OPTIONS_STRING" value="" /> + <option name="MAXIMUM_HEAP_SIZE" value="128" /> + <option name="USE_GENERICS_COMPILER" value="false" /> + </component> + <component name="JavadocGenerationManager"> + <option name="OUTPUT_DIRECTORY" /> + <option name="OPTION_SCOPE" value="protected" /> + <option name="OPTION_HIERARCHY" value="true" /> + <option name="OPTION_NAVIGATOR" value="true" /> + <option name="OPTION_INDEX" value="true" /> + <option name="OPTION_SEPARATE_INDEX" value="true" /> + <option name="OPTION_DOCUMENT_TAG_USE" value="false" /> + <option name="OPTION_DOCUMENT_TAG_AUTHOR" value="false" /> + <option name="OPTION_DOCUMENT_TAG_VERSION" value="false" /> + <option name="OPTION_DOCUMENT_TAG_DEPRECATED" value="true" /> + <option name="OPTION_DEPRECATED_LIST" value="true" /> + <option name="OTHER_OPTIONS" value="" /> + <option name="HEAP_SIZE" /> + <option name="OPEN_IN_BROWSER" value="true" /> + </component> + <component name="JikesSettings"> + <option name="JIKES_PATH" value="" /> + <option name="DEBUGGING_INFO" value="true" /> + <option name="DEPRECATION" value="true" /> + <option name="GENERATE_NO_WARNINGS" value="false" /> + <option name="IS_EMACS_ERRORS_MODE" value="true" /> + <option name="ADDITIONAL_OPTIONS_STRING" value="" /> + </component> + <component name="PEExternalization"> + <option name="IGNORE_METHOD_NAMES" value="" /> + <option name="IGNORE_METHOD_NAMES_ENABLED" value="false" /> + <option name="IGNORE_CLASS_CONSTRUCTORS"> + <value> + <option class="Exception" includeInheritors="true" /> + </value> + </option> + <option name="IGNORE_CLASS_CONSTRUCTOR_NAMES_ENABLED" value="true" /> + <option name="IGNORE_CLASS_METHODS_ENABLED" value="true" /> + <option name="IGNORE_STRINGS_CONTAINS_ONLY_ENABLED" value="true" /> + <option name="IGNORE_STRINGS_CONTAINS_ONLY_WHITESPACES" value="true" /> + <option name="IGNORE_STRINGS_CONTAINS_ONLY_PUNCTUATIONS" value="true" /> + <option name="IGNORE_STRINGS_CONTAINS_ONLY_SPECIFIED_ENABLED" value="true" /> + <option name="IGNORE_STRINGS_CONTAINS_ONLY_SPECIFIED" value="" /> + <option name="IGNORE_CLASS_METHODS"> + <value> + <option class="Exception" includeInheritors="false" /> + <option class="java.util.ResourceBundle" includeInheritors="true" /> + </value> + </option> + <option name="IGNORE_CONSTANTS_DECLARATIONS" value="true" /> + </component> + <component name="Palette2"> + <group name="Swing"> + <item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false"> + <default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" /> + </item> + <item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false"> + <default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" /> + </item> + <item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false"> + <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" /> + </item> + <item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false"> + <default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" /> + </item> + <item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false"> + <default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" /> + <initial-values> + <property name="text" value="Button" /> + </initial-values> + </item> + <item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false"> + <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" /> + <initial-values> + <property name="text" value="RadioButton" /> + </initial-values> + </item> + <item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false"> + <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" /> + <initial-values> + <property name="text" value="CheckBox" /> + </initial-values> + </item> + <item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false"> + <default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" /> + <initial-values> + <property name="text" value="Label" /> + </initial-values> + </item> + <item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false"> + <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> + <preferred-size width="150" height="-1" /> + </default-constraints> + </item> + <item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false"> + <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> + <preferred-size width="150" height="-1" /> + </default-constraints> + </item> + <item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false"> + <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> + <preferred-size width="150" height="-1" /> + </default-constraints> + </item> + <item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false"> + <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> + <preferred-size width="150" height="50" /> + </default-constraints> + </item> + <item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false"> + <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> + <preferred-size width="150" height="50" /> + </default-constraints> + </item> + <item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false"> + <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> + <preferred-size width="150" height="50" /> + </default-constraints> + </item> + <item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false"> + <default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" /> + </item> + <item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false"> + <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> + <preferred-size width="150" height="50" /> + </default-constraints> + </item> + <item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false"> + <default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3"> + <preferred-size width="150" height="50" /> + </default-constraints> + </item> + <item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false"> + <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> + <preferred-size width="150" height="50" /> + </default-constraints> + </item> + <item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false"> + <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3"> + <preferred-size width="200" height="200" /> + </default-constraints> + </item> + <item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false"> + <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3"> + <preferred-size width="200" height="200" /> + </default-constraints> + </item> + <item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false"> + <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" /> + </item> + <item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false"> + <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" /> + </item> + </group> + </component> + <component name="ProjectModuleManager"> + <modules> + <module fileurl="file://$PROJECT_DIR$/SedaRedesign.iml" filepath="$PROJECT_DIR$/SedaRedesign.iml" /> + </modules> + </component> + <component name="ProjectRootManager" version="2" assert-keyword="true" jdk-15="false" project-jdk-name="java version "1.5.0"" /> + <component name="RmicSettings"> + <option name="IS_EANABLED" value="false" /> + <option name="DEBUGGING_INFO" value="true" /> + <option name="GENERATE_NO_WARNINGS" value="false" /> + <option name="GENERATE_IIOP_STUBS" value="false" /> + <option name="ADDITIONAL_OPTIONS_STRING" value="" /> + </component> + <component name="TCPMON" /> + <component name="TDDConfig"> + <option name="idleMsBeforeTimerPause" value="300000" /> + <option name="masterSuiteConfigurationName" /> + <option name="rollingActivityCycleTimelineSampleSize" value="40" /> + </component> + <component name="copyright"> + <option name="body" value="/* * Copyright 2004 The Apache Software Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */" /> + <option name="location" value="1" /> + <option name="remove" value="true" /> + <option name="replace" value="2" /> + </component> + <component name="libraryTable" /> + <component name="uidesigner-configuration"> + <option name="INSTRUMENT_CLASSES" value="true" /> + <option name="COPY_FORMS_RUNTIME_TO_OUTPUT" value="true" /> + </component> +</project> + Modified: incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/input/ConnectSource.java Url: http://svn.apache.org/viewcvs/incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/input/ConnectSource.java?view=diff&rev=109997&p1=incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/input/ConnectSource.java&r1=109996&p2=incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/input/ConnectSource.java&r2=109997 ============================================================================== --- incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/input/ConnectSource.java (original) +++ incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/input/ConnectSource.java Mon Dec 6 10:03:19 2004 @@ -19,6 +19,8 @@ import org.d_haven.event.Source; import java.nio.channels.Selector; +import java.nio.channels.SelectableChannel; +import java.nio.channels.SelectionKey; import java.io.IOException; import java.util.Iterator; import java.util.List; @@ -97,11 +99,27 @@ } } - public void listen( final int port ) + public void listen( final ServerSocket socket ) throws IOException { + final SelectableChannel channel = socket.getChannel(); + if ( channel.isBlocking() ) + { + channel.configureBlocking( false ); + } + + channel.register( m_selector, SelectionKey.OP_ACCEPT ); + } + + public void unlisten( final ServerSocket socket ) + { + final SelectableChannel channel = socket.getChannel(); + + final SelectionKey key = channel.keyFor( m_selector ); + key.cancel(); } - public void unlisten( final int port ) + public void close() throws IOException { + m_selector.close(); } } Modified: incubator/directory/seda/branches/berin_api_proposal/src/test/org/apache/directory/seda/input/test/TestConnectSource.java Url: http://svn.apache.org/viewcvs/incubator/directory/seda/branches/berin_api_proposal/src/test/org/apache/directory/seda/input/test/TestConnectSource.java?view=diff&rev=109997&p1=incubator/directory/seda/branches/berin_api_proposal/src/test/org/apache/directory/seda/input/test/TestConnectSource.java&r1=109996&p2=incubator/directory/seda/branches/berin_api_proposal/src/test/org/apache/directory/seda/input/test/TestConnectSource.java&r2=109997 ============================================================================== --- incubator/directory/seda/branches/berin_api_proposal/src/test/org/apache/directory/seda/input/test/TestConnectSource.java (original) +++ incubator/directory/seda/branches/berin_api_proposal/src/test/org/apache/directory/seda/input/test/TestConnectSource.java Mon Dec 6 10:03:19 2004 @@ -21,7 +21,11 @@ import java.net.ServerSocket; import java.net.Socket; import java.net.InetAddress; +import java.net.InetSocketAddress; import java.io.IOException; +import java.nio.channels.ServerSocketChannel; +import java.nio.channels.SelectionKey; +import java.nio.channels.SocketChannel; import org.apache.directory.seda.input.ConnectSource; @@ -33,6 +37,9 @@ { private static final int PORT = 6666; private ServerSocket m_socket; + private ServerSocketChannel m_channel; + private SocketChannel m_clientChannel; + private ConnectSource m_source; public TestConnectSource(final String name) { @@ -43,24 +50,93 @@ { super.setUp(); - m_socket = new ServerSocket(PORT); + m_channel = ServerSocketChannel.open(); + m_socket = m_channel.socket(); + m_socket.bind( new InetSocketAddress(PORT) ); + + m_clientChannel = SocketChannel.open(); + m_clientChannel.configureBlocking( false ); + + m_source = new ConnectSource(); + m_source.listen(m_socket); } public void tearDown() throws Exception { super.tearDown(); + m_source.unlisten(m_socket); + m_source.close(); + m_socket.close(); + m_clientChannel.close(); + m_channel.close(); } public void testConnectStage() throws IOException { - final ConnectSource source = new ConnectSource(); - source.listen(PORT); + final Socket client = new Socket(InetAddress.getLocalHost(), PORT); + assertTrue(client.isConnected()); + + m_source.dequeueAll(); + client.close(); + } + + public void testDequeue() throws IOException + { + m_clientChannel.connect( new InetSocketAddress(InetAddress.getLocalHost(), PORT) ); + final Object key; + + System.out.println(m_clientChannel.isConnectionPending()); + System.out.println(m_clientChannel.isConnected()); + + key = m_source.dequeue(); + + assertNotNull( key ); + assertTrue( key instanceof SelectionKey ); + assertEquals( m_channel, ((SelectionKey)key).channel() ); + assertTrue(m_clientChannel.isConnected()); + } + + public void testDequeue_many() throws IOException + { final Socket client = new Socket(InetAddress.getLocalHost(), PORT); assertTrue(client.isConnected()); - source.unlisten(PORT); + final Object[] key = m_source.dequeue(1); + assertNotNull( key ); + assertEquals( 1, key.length ); + assertTrue( key[0] instanceof SelectionKey ); + assertEquals( m_channel, ((SelectionKey)key[0]).channel() ); + + client.close(); + } + + public void testDequeue_all() throws IOException + { + final Socket client = new Socket(InetAddress.getLocalHost(), PORT); + assertTrue(client.isConnected()); + + final Object[] key = m_source.dequeueAll(); + assertNotNull( key ); + assertEquals( 1, key.length ); + assertTrue( key[0] instanceof SelectionKey ); + assertEquals( m_channel, ((SelectionKey)key[0]).channel() ); + + client.close(); + } + + public void testSize_setTimeout() throws IOException + { + final Socket client = new Socket(InetAddress.getLocalHost(), PORT); + assertTrue(client.isConnected()); + + m_source.setTimeout( 1L ); // does nothing + assertEquals( 1, m_source.size() ); + + m_source.dequeueAll(); + + client.close(); } }
