geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgenen...@apache.org
Subject svn commit: r465926 - in /geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp: AbstractServer.java TCPEndpointTest.java TCPNotification.java TCPSocketServerTest.java
Date Thu, 19 Oct 2006 23:14:33 GMT
Author: jgenender
Date: Thu Oct 19 16:14:32 2006
New Revision: 465926

URL: http://svn.apache.org/viewvc?view=rev&rev=465926
Log:
Add tests to show multiple client updates

Added:
    geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/TCPNotification.java
  (with props)
Modified:
    geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/AbstractServer.java
    geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/TCPEndpointTest.java
    geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/TCPSocketServerTest.java

Modified: geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/AbstractServer.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/AbstractServer.java?view=diff&rev=465926&r1=465925&r2=465926
==============================================================================
--- geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/AbstractServer.java
(original)
+++ geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/AbstractServer.java
Thu Oct 19 16:14:32 2006
@@ -41,6 +41,7 @@
 
     protected TransportServer server = null;
     protected Socket client;
+    protected Socket client2;
     protected CacheInfoHolder info;
     
     @BeforeClass
@@ -56,6 +57,10 @@
         //Create a client socket
         client = new Socket();
         client.connect(new InetSocketAddress(host, port),2000);
+        
+        //Create a second client socket
+        client2 = new Socket();
+        client2.connect(new InetSocketAddress(host, port),2000);
     }
 
     @AfterClass(alwaysRun=true)
@@ -63,23 +68,24 @@
         server.stop();
         
         client.close();
+        client2.close();
     }
     
-    protected void sendCommand(BaseCommand command) throws IOException{
+    protected void sendCommand(Socket socket, BaseCommand command) throws IOException{
 	
 	byte bytes[] = command.createPacket(true);
 	
-	OutputStream out = client.getOutputStream();
+	OutputStream out = socket.getOutputStream();
 	out.write(bytes);
 	out.flush();
 	
     }
     
-    protected Command readCommand() throws IOException{
+    protected Command readCommand(Socket socket) throws IOException{
 	
 	byte recBuf[] = new byte[Constants.HEADER_SIZE];
 	
-        InputStream is = client.getInputStream();
+        InputStream is = socket.getInputStream();
         int read = is.read(recBuf);
         assert read == Constants.HEADER_SIZE;
 	ByteBuffer receiveHeader = ByteBuffer.wrap(recBuf);

Modified: geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/TCPEndpointTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/TCPEndpointTest.java?view=diff&rev=465926&r1=465925&r2=465926
==============================================================================
--- geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/TCPEndpointTest.java
(original)
+++ geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/TCPEndpointTest.java
Thu Oct 19 16:14:32 2006
@@ -38,10 +38,10 @@
 	command.setCacheName("Cache1");
 	
         //Send the packet
-	sendCommand(command);
+	sendCommand(client, command);
 	
         //Now receive any data (it Should be a BulkSendCommand)
-        Command bulk = this.readCommand(); 
+        Command bulk = this.readCommand(client); 
 
         //Is the message the type we think it is?
         assert bulk instanceof BulkSendCommand;

Added: geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/TCPNotification.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/TCPNotification.java?view=auto&rev=465926
==============================================================================
--- geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/TCPNotification.java
(added)
+++ geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/TCPNotification.java
Thu Oct 19 16:14:32 2006
@@ -0,0 +1,97 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+package org.apache.geronimo.gcache.transports.tcp;
+
+import java.net.Socket;
+import java.nio.ByteBuffer;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.geronimo.gcache.command.BulkSendCommand;
+import org.apache.geronimo.gcache.command.Command;
+import org.apache.geronimo.gcache.command.GetCacheCommand;
+import org.apache.geronimo.gcache.command.MessageAckCommand;
+import org.apache.geronimo.gcache.command.PutSessionCommand;
+import org.testng.annotations.Test;
+
+public class TCPNotification extends AbstractServer {
+    
+    @Test
+    public void notificationTest() throws Exception{
+	
+	GetCacheCommand command = new GetCacheCommand();
+	
+	command.setCacheName("Test");
+	
+	//Send the getCache request from client 1
+	sendCommand(client, command);
+	Command ack = readCommand(client);
+	assert ack instanceof BulkSendCommand;
+	
+	//Send the getCache request from client 2
+	sendCommand(client2, command);
+	ack = readCommand(client2);
+	assert ack instanceof BulkSendCommand;
+	
+	//Send a session
+	sendSession(client);
+	
+	//Client 2 should have a notification 
+	Command read = readCommand(client2);
+	assert read instanceof PutSessionCommand;
+	
+	Map session = ((PutSessionCommand) read).getSessionFromPayload();
+	assert session.size() == 3;
+	
+	assert ((PutSessionCommand) read).getCacheName().equals("Cache1");
+	
+	assert session.containsKey("key1");
+	assert session.containsKey("key2");
+	assert session.containsKey("key3");
+	
+	assert ((String)session.get("key1")).equals("data1");
+	assert ((String)session.get("key2")).equals("data2");
+	assert ((String)session.get("key3")).equals("data3");
+    }
+    
+    private void sendSession(Socket socket) throws Exception{
+	
+        //Create a session
+        Map<String,String> session = new HashMap<String, String>();
+        session.put("key1","data1");
+        session.put("key2","data2");
+        session.put("key3","data3");
+        PutSessionCommand command = new PutSessionCommand();
+        command.setCacheName("Cache1");
+        command.setSessionId("Session1");
+        command.setPayloadFromSession(session);
+
+        //Send the packet
+        ByteBuffer commandBuffer = ByteBuffer.wrap(command.createPacket(true));
+        commandBuffer.flip();
+        sendCommand(socket, command);
+
+        //Now receive any data (it Should be a MessageAck)
+        Command ackCommand = this.readCommand(socket); 
+
+        //Is the message the type we think it is?
+        assert ackCommand instanceof MessageAckCommand;
+	
+    }
+
+}

Propchange: geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/TCPNotification.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/TCPNotification.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/TCPNotification.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/TCPSocketServerTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/TCPSocketServerTest.java?view=diff&rev=465926&r1=465925&r2=465926
==============================================================================
--- geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/TCPSocketServerTest.java
(original)
+++ geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/TCPSocketServerTest.java
Thu Oct 19 16:14:32 2006
@@ -43,10 +43,10 @@
         //Send the packet
         ByteBuffer commandBuffer = ByteBuffer.wrap(command.createPacket(true));
         commandBuffer.flip();
-        sendCommand(command);
+        sendCommand(client, command);
 
         //Now receive any data (it Should be a MessageAck)
-        Command ackCommand = this.readCommand(); 
+        Command ackCommand = this.readCommand(client); 
 
         //Is the message the type we think it is?
         assert ackCommand instanceof MessageAckCommand;



Mime
View raw message