geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgenen...@apache.org
Subject svn commit: r408925 [3/3] - in /geronimo/sandbox/geronimo-cache: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/geronimo/ src/main/java/org/apache/geronimo/cache/ src/main/java/org/apache/geronimo...
Date Tue, 23 May 2006 15:13:55 GMT
Added: geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/comm/MessageIDTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/comm/MessageIDTest.java?rev=408925&view=auto
==============================================================================
--- geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/comm/MessageIDTest.java
(added)
+++ geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/comm/MessageIDTest.java
Tue May 23 08:13:52 2006
@@ -0,0 +1,111 @@
+/*
+ * Copyright 2005-2006 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.
+ */
+package org.apache.geronimo.cache.comm;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+
+import junit.framework.TestCase;
+
+/**
+ * 
+ * $Rev$ $Date$
+ */
+public class MessageIDTest extends TestCase {
+
+	public static void main(String[] args) {
+		junit.textui.TestRunner.run(MessageIDTest.class);
+	}
+
+	public MessageIDTest(String arg0) {
+		super(arg0);
+	}
+
+	protected void setUp() throws Exception {
+		super.setUp();
+	}
+
+	protected void tearDown() throws Exception {
+		super.tearDown();
+	}
+
+	/*
+	 * Test method for 'org.apache.geronimo.cache.comm.MessageID.hashCode()'
+	 */
+	public void testHashCode() {
+		MessageID id = new MessageID();
+		assertFalse(id.hashCode() == (new MessageID()).hashCode());
+		assertEquals(id.hashCode(), id.hashCode());
+	}
+
+	/*
+	 * Test method for 'org.apache.geronimo.cache.comm.MessageID.equals(Object)'
+	 */
+	public void testEqualsObject() throws Exception {
+		MessageID id = new MessageID();
+		assertNotSame(id, new MessageID());
+		assertEquals(id, id);
+		ByteArrayOutputStream baos = new ByteArrayOutputStream(64);
+		DataOutputStream out = new DataOutputStream(baos);
+		id.write(out);
+		out.flush();
+		ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+		DataInputStream in = new DataInputStream(bais);
+		MessageID id2 = MessageID.read(in);
+		assertEquals(id2, id);
+	}
+
+	/*
+	 * Test method for
+	 * 'org.apache.geronimo.cache.comm.MessageID.write(DataOutput)'
+	 */
+	public void testWrite() throws Exception {
+		MessageID id = new MessageID();
+		ByteArrayOutputStream baos = new ByteArrayOutputStream(64);
+		DataOutputStream out = new DataOutputStream(baos);
+		id.write(out);
+		out.flush();
+		// should always be 26 unless something goes wrong with getting the
+		// localhost
+		// from InetAddress
+		assertEquals(26, baos.toByteArray().length);
+	}
+
+	/*
+	 * Test method for
+	 * 'org.apache.geronimo.cache.comm.MessageID.read(DataInput)'
+	 */
+	public void testRead() throws Exception {
+		ByteArrayOutputStream baos = new ByteArrayOutputStream(64);
+		DataOutputStream out = new DataOutputStream(baos);
+		out.writeInt("hello".hashCode());
+		out.writeLong(System.currentTimeMillis());
+		out.writeShort((short) 14);
+		byte spoofAddressHash[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
+		out.writeInt(spoofAddressHash.length);
+		out.write(spoofAddressHash);
+		out.flush();
+		byte data[] = baos.toByteArray();
+		out.close();
+		DataInputStream in = new DataInputStream(new ByteArrayInputStream(data));
+		MessageID id = MessageID.read(in);
+		// this does no really test anything...
+		assertNotNull(id);
+	}
+
+}

Added: geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/comm/MockCacheChannel.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/comm/MockCacheChannel.java?rev=408925&view=auto
==============================================================================
--- geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/comm/MockCacheChannel.java
(added)
+++ geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/comm/MockCacheChannel.java
Tue May 23 08:13:52 2006
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2005-2006 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.
+ */
+package org.apache.geronimo.cache.comm;
+
+import org.apache.geronimo.cache.ReplicatedCache;
+
+/**
+ * 
+ * $Rev$ $Date$
+ */
+public class MockCacheChannel implements CacheChannel {
+	private int receiveCount = 0;
+
+	private int sendCount = 0;
+
+	private boolean sendEvents = true;
+
+	public void close() {
+	}
+
+	public ReplicatedCache getCache() {
+		return null;
+	}
+
+	public void recieve(RemoteEvent update) {
+		receiveCount++;
+	}
+
+	public void send(RemoteEvent update) {
+		if (sendEvents) {
+			sendCount++;
+		}
+	}
+
+	public void setCache(ReplicatedCache cache) {
+	}
+
+	public void setSendEvents(boolean flag) {
+		sendEvents = flag;
+	}
+
+	public int getSendCount() {
+		return sendCount;
+	}
+
+}

Added: geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/comm/RunCacheStuff.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/comm/RunCacheStuff.java?rev=408925&view=auto
==============================================================================
--- geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/comm/RunCacheStuff.java
(added)
+++ geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/comm/RunCacheStuff.java
Tue May 23 08:13:52 2006
@@ -0,0 +1,111 @@
+/*
+ * Copyright 2005-2006 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.
+ */
+package org.apache.geronimo.cache.comm;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.InetAddress;
+import java.net.NetworkInterface;
+import java.net.SocketException;
+import java.net.UnknownHostException;
+import java.util.Enumeration;
+import java.util.Iterator;
+
+import org.apache.geronimo.cache.ReplicatedCache;
+import org.apache.geronimo.cache.comm.impl.CacheCommListener;
+import org.apache.geronimo.cache.comm.impl.CacheChannelUDPImpl;
+import org.apache.geronimo.cache.impl.ReplicatedCacheImpl;
+
+/**
+ * 
+ * $Rev$ $Date$
+ */
+public class RunCacheStuff {
+	public static void main(String args[]) {
+		CacheChannel channel = new CacheChannelUDPImpl();
+		ReplicatedCache cache = new ReplicatedCacheImpl(channel);
+		CacheCommListener listener = new CacheCommListener(channel);
+		cache.addListener(listener);
+		printoutNetStuff(false);
+		int i = 0;
+		while (true) {
+			BufferedReader reader = new BufferedReader(new InputStreamReader(
+					System.in));
+			String value = null;
+			try {
+				value = reader.readLine();
+			} catch (IOException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			}
+			if (null != value && !value.equals("q") && !value.equals("p")) {
+				cache.put(cache.getId() + ":" + (i++), cache.getName() + ":"
+						+ i);
+			} else if (null != value && value.equals("p")) {
+				System.out.println("cache.id = " + cache.getId());
+				Iterator itr = cache.keySet().iterator();
+				while (itr.hasNext()) {
+					Object key = itr.next();
+					System.out.println("key -> " + key + " value -> "
+							+ cache.get(key));
+				}
+			} else {
+				channel.close();
+				break;
+			}
+		}
+	}
+
+	private static void printoutNetStuff(boolean flag) {
+		if (flag) {
+			try {
+				Enumeration ifEnum = NetworkInterface.getNetworkInterfaces();
+				InetAddress localAddr = InetAddress.getLocalHost();
+				System.out.println("localAddr.hostname = "
+						+ localAddr.getHostName());
+				System.out.println("localAddr.can hostname = "
+						+ localAddr.getCanonicalHostName());
+				System.out.println("localAddr.addr = "
+						+ localAddr.getHostAddress());
+				while (ifEnum.hasMoreElements()) {
+					NetworkInterface netFace = (NetworkInterface) ifEnum
+							.nextElement();
+					System.out.println("net face name = "
+							+ netFace.getDisplayName());
+					Enumeration addEnum = netFace.getInetAddresses();
+					while (addEnum.hasMoreElements()) {
+						InetAddress add = (InetAddress) addEnum.nextElement();
+						System.out.println("hostname = " + add.getHostName());
+						System.out.println("canonical hostname = "
+								+ add.getCanonicalHostName());
+						System.out.println("ip = " + add.getHostAddress());
+					}
+					InetAddress local = InetAddress.getLocalHost();
+					System.out.println("hostname = "
+							+ local.getCanonicalHostName());
+					System.out.println("ip = " + local.getHostAddress());
+				}
+			} catch (SocketException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			} catch (UnknownHostException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			}
+		}
+	}
+}

Added: geronimo/sandbox/geronimo-cache/src/test/resources/META-INF/geronimo-cache-config.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-cache/src/test/resources/META-INF/geronimo-cache-config.xml?rev=408925&view=auto
==============================================================================
--- geronimo/sandbox/geronimo-cache/src/test/resources/META-INF/geronimo-cache-config.xml
(added)
+++ geronimo/sandbox/geronimo-cache/src/test/resources/META-INF/geronimo-cache-config.xml
Tue May 23 08:13:52 2006
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- 
+ * Copyright 2005-2006 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.
+ -->
+<cache:cache-config
+	xmlns:cache="http://geronimo.apache.org/xml/ns/cache-1.0"
+	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://geronimo.apache.org/xml/ns/cache-1.0 ../../../main/xsd/geronimo-cache-1.0.xsd
">
+
+	<cache:cache cacheName="testCache" evictionPolicy="LEAST_RECENTLY_USED">
+		<cache:cache-impl>org.apache.geronimo.cache.impl.LocalCacheImpl</cache:cache-impl>
+		<cache:storageRef storageNameRef="testStorage" />
+	</cache:cache>
+
+	<cache:storage storageName="testStorage">
+		<cache:storage-strategy>MEMORY</cache:storage-strategy>
+	</cache:storage>
+
+</cache:cache-config>



Mime
View raw message