Subversion Repositories SmartDukaan

Rev

Blame | Last modification | View Log | RSS feed

package in.shop2020.alert.test;

import java.util.Date;

import in.shop2020.alert.AlertMapper;
import in.shop2020.alert.AlertService.Client;
import in.shop2020.alert.AlertServiceException;
import in.shop2020.alert.AlertType;
import in.shop2020.alert.EntityProcessedState;
import in.shop2020.alert.EntityType;
import in.shop2020.alert.MonitoredEntity;
import in.shop2020.alert.SearchFilter;

import org.apache.thrift.TException;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TFramedTransport;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport;
import org.apache.thrift.transport.TTransportException;

public class TestAlertServer {
        private static final int SOCKET_TIMEOUT = 1000 * 60 * 5;
        
        public static void main(String[] args) throws AlertServiceException{
                TSocket socket = new TSocket("localhost", 9018);
                socket.setTimeout(SOCKET_TIMEOUT);
                
                TTransport transport = new TFramedTransport(socket);
                TProtocol protocol = new TBinaryProtocol(transport);
                Client client = new Client(protocol);
                try {
                        transport.open();
                } catch (TTransportException e) {
                        e.printStackTrace();
                }
                
                try {
//                      MonitoredEntity entity = new MonitoredEntity();
//                      entity.setEntityType(EntityType.ORDER);
//                      entity.setEventType(3);
//                      entity.setEntityIdentifier("testing insertion");
//                      entity.setWarnExpiryTime(new Date().UTC(2012, 6, 21, 18, 35, 0));
//                      entity.setWarnExpiryTime(new Date().UTC(2012, 6, 22, 11, 45, 0));
//                      entity.setDescription("Test Order entity");
//                      entity.setEntityProcessedState(EntityProcessedState.WARNING_SENT);
//                      client.scheduleAlert(entity);
//                      client.updateMonitoredObject(entity);
//                      client.endMonitoringEntity(EntityType.ORDER, "123");
//                      client.deActivateEntityMonitoring(EntityType.ORDER);
//                      client.activateEntityMonitoring(EntityType.ORDER, "amar.kumar@shop2020.in");
//                      AlertMapper alertMap = new AlertMapper();
//                      alertMap.setEntityType(EntityType.ORDER);
//                      alertMap.setEventType(2);
//                      alertMap.setEventdesciption("TEst");
//                      alertMap.setAlertType(AlertType.EMAIL);
//                      alertMap.setUserIds("amar.kumar@shop2020.in");
//                      client.registerEventType(alertMap);
//                      client.updateMonitoredObject(entity);
//                      SearchFilter searchFilter = new SearchFilter();
//                      searchFilter.setEntityProcessedState(EntityProcessedState.UNEXPIRED);
//                      System.out.println(client.getEntities(searchFilter));
                        System.out.println(client.getAlertMapper(EntityType.ORDER, 3));
                } catch (TException e) {
                        e.printStackTrace();
                } catch (AlertServiceException ex) {
                        ex.printStackTrace();
                }
        }
}