2
* Copyright (C) 2009 by Eric Herman <eric@freesa.org>
3
* Use and distribution licensed under the
4
* GNU Lesser General Public License (LGPL) version 2.1.
5
* See the COPYING file in the parent directory for full text.
7
package org.gearman.common;
9
import java.util.LinkedList;
10
import java.util.List;
11
import java.util.Queue;
13
import org.gearman.util.ByteUtils;
15
public class MockConnection extends ThrowingConnection {
17
private boolean opened;
18
private boolean closed;
19
private List<String> canDo;
20
private List<String> cantDo;
21
private List<String> clientId;
23
protected Queue<GearmanPacket> readQueue;
24
protected List<GearmanPacket> written;
26
public MockConnection() {
30
canDo = new LinkedList<String>();
31
cantDo = new LinkedList<String>();
32
clientId = new LinkedList<String>();
34
readQueue = new LinkedList<GearmanPacket>();
35
written = new LinkedList<GearmanPacket>();
48
public GearmanPacket read() {
49
if (!readQueue.isEmpty()) {
50
return readQueue.poll();
52
throw new RuntimeException("unexpected read");
55
public void write(Packet request) {
57
PacketType packetType = request.getPacketType();
60
clientId.add(ByteUtils.fromAsciiBytes(request.getData()));
63
canDo.add(ByteUtils.fromAsciiBytes(request.getData()));
66
cantDo.add(ByteUtils.fromAsciiBytes(request.getData()));
73
public boolean isOpen() {
77
public boolean wasOpened() {
81
public boolean wasClosed() {
85
public List<String> clientId() {
89
public List<String> canDo() {
93
public List<String> cantDo() {