Esempio n. 1
0
    def cleanUp(self):
        global remoteSubList
        global virTableList
        global targetTableList
        global remoteTableList
        global src


        conman = ConnectionManager(verbosity=self._verbosity)
        self.conn = conman.createConnection(autocommit=True)
        cursor = self.conn.cursor()

        consrc = ConnectionManager()
        self.conn_src = consrc.createConnection(address=src['pds_host_name'], port=int(src['pds_database_port']), user="******", password=src['system_password'],autocommit=True)
        cursor_src = self.conn_src.cursor()

        testapi = DPAdapterApi(self.conn, cursor)
        testSrc = DPAdapterRemoteHDB(self.conn_src, cursor_src)

        try:
            if len(remoteSubList) > 0:
                try:
                    testapi.dropRemoteSubscription(subName, "SYSTEM")
                except Exception as e:
                    pass

            if len(targetTableList) > 0:
                try:
                    testapi.dropTargetTable(tableName, "SYSTEM")
                except Exception as e:
                    pass
            if len(virTableList) > 0:
                try:
                    testapi.dropVirtualTable(tableName, "SYSTEM")
                except Exception as e:
                    pass

	    print 'drop remote source "HDBAdapterSrc" cascade'
            try:
                self.execute('drop remote source "' + src['RemoteSourceName'] + '" cascade')
            except Exception as e:
                pass
	    print 'drop adapter "HanaAdapter" cascade'
            try:
                self.execute('drop adapter "HanaAdapter" cascade')
            except Exception as e:
                pass
	    print 'drop agent "' , self.agent_name , '"'
            try:
                self.execute('drop agent "' + self.agent_name + '"')
            except Exception as e:
                pass
	    print 'cleanup done'
            self.dp.appendTrace('cleanup done')
        except dbapi.Error, err:
            self.dp.appendTrace('Error in cleanup')
            self.dp.appendTrace(str(err))
            pass
Esempio n. 2
0
    def getSecret(self, username, message):
        """ Start chatting with the bot server. GLADOS replies back to the client socket
            so we have to keep the connection open and wait to receive replies from bot. """

        try:
            if len(self.__userList) == 0:
                raise Exception, 'Use the list command to see the online users'

            if (username in self.__userList):

                uIp, uP = self.__userList[username]
                c = ConnectionManager(uIp, uP)
                c.connect()
                c.send(p.T_MESSAGE, [self.__username], message)

                # We wait for four replies from GLADOS to receive the final token
                # The application is going to block until GLADOS replies.
                # Quick and dirty solution as GLaDOS speaks "differently" from
                # the way this client is implemented. So, the message is printed
                # in raw format just to get the final token.
                for i in range(0, 3):
                    r = c.receive()
                    self.__agent.printMessage(str(r), 'Bot user')
                    if (r.type == p.T_PING):
                        c.send(p.T_PONG, [self.__username])
                c.disconnect()
            else:
                raise Exception, 'User %s can\'t be reached.' % username

        except Exception, e:
            self.__handleError('Chat', e)
Esempio n. 3
0
    def __init__(self, ip, port, verbose=False):
        super().__init__()

        # Set up mouse input
        base.cTrav = CollisionTraverser()
        self.handler = CollisionHandlerQueue()
        self.mouseHandler = MouseHandler()
        self.taskMgr.add(self.inputTask, "InputTask")

        # Set up the UI
        self.fonts = hud.hud.Fonts()
        self._scene = None

        # Set up audio
        self.audioMaster = audio.AudioMaster()

        # Set up the NetworkManager
        self.client = protocol.client.Client(ip, port, verbose)
        instr = networkInstructions.NetworkInstructions(self)
        self.client.add_observer(instr)

        self.clientActions = self.client.clientActions
        self.gameState = self.client.state

        # Connect to the server
        self.scene = hud.connection.ConnectionUI()
        self.connectionManager = ConnectionManager((ip, port), self, self.scene)
        self.connectionManager.tryConnect()
        self.taskMgr.add(self.networkUpdateTask, "NetworkUpdateTask")
Esempio n. 4
0
    def compareRepData(self, selectSql, resultset, timeout=300):
        """
        Define compareRepData inside of test class to generate the new expect result file named DPAdapterAAsimpleDPHANATest
        The expected result set file has limitation of 10M size. Existing DPAdapterDataCompareExpected.py contains too many resultsets.
        When the file size exceed 10m, we have to put the file to /area51 and also need many extra steps to let test find the file.
        See more details on the limitation at:
        http://trexweb.wdf.sap.corp:1080/wiki/index.php/PyUnit_Test_Framework
        """
        conman = ConnectionManager(verbosity=self._verbosity)
        self.conn = conman.createConnection(autocommit=True)
        cursor = self.conn.cursor()

        msg = "compareRepData:" + selectSql + ":" + str(resultset)
        loggerTest.info(msg)

        wait_period = os.getenv('WAIT_PERIOD')
        if wait_period != None:
            timeout = int(wait_period)

        if timeout < 0:
            loggerTest.info("Illegal timeout value given. Acceptable value should be >= 0, will use default value 300 (seconds).")
            timeout = 300

        # check only once if timeout = 0
        intv = 5
        if timeout == 0:
            try:
                cursor.execute(selectSql)
                e = ExpectedSimpleResultSet(cursor)
                self.assertExpected(e, resultset, "Data not replicated correctly to HANA.")
            except Exception as err:
                raise
        else:
            # check data within timeout seconds
            wait_time = 0
            while (wait_time < timeout):
                try:
                    cursor.execute(selectSql)
                    e = ExpectedSimpleResultSet(cursor)
                    if self.assertExpected(e, resultset, "Data not replicated correctly to HANA.") is None:
                        break
                except Exception as err:
                    time.sleep(intv)
                    wait_time = wait_time + intv
                    msg = "wait " + str(wait_time) + " sec"
                    loggerTest.info(msg)

            if wait_time >= timeout:
                errmsg = "Data not replicated correctly to HANA after waiting for " + str(timeout) + " seconds."
                try:
                    cursor.execute(selectSql)
                    e = ExpectedSimpleResultSet(cursor)
                    self.assertExpected(e, resultset, errmsg)
                except Exception as err:
                    raise
Esempio n. 5
0
    def init(self):
        self._nodeManager = NodeManager()
        self._connectionManager = ConnectionManager()
        self._viewerManager = ViewerManager()

        # connect undoRedoChanged signal
        self._nodeManager.undoRedoChanged.connect(self.emitUndoRedoChanged)
        self._connectionManager.undoRedoChanged.connect(
            self.emitUndoRedoChanged)
        self._viewerManager.undoRedoChanged.connect(self.emitUndoRedoChanged)

        return self
Esempio n. 6
0
    def chat(self, username, message, getSecret=False):
        """ Start chatting with a specific user """

        try:
            if len(self.__userList) == 0:
                raise Exception, 'Use the list command to see the online users'

            if (username in self.__userList):

                # Setup a new socket connection with the other user and send data.
                # The user can reply at the binded port from the directory server
                uIp, uP = self.__userList[username]
                c = ConnectionManager(uIp, uP)
                c.connect()
                c.send(p.T_MESSAGE, [self.__username], message)
                c.disconnect()

            else:
                raise Exception, 'User %s can\'t be reached.' % username

        except Exception, e:
            self.__handleError('Chat', e)
Esempio n. 7
0
    def ping(self, username):
        """ Ping user """

        try:
            if len(self.__userList) == 0:
                raise Exception, 'Use the list command to see the online users'

            if (username in self.__userList):

                uIp, uP = self.__userList[username]
                c = ConnectionManager(uIp, uP)

                c.connect()
                c.send(p.T_PING, [self.__username])

                pong = c.receive()
                self.__agent.printMessage(pong.type, pong.args.pop())

                c.disconnect()
            else:
                raise Exception, 'User %s can\'t be pinged.' % username

        except Exception, e:
            self.__handleError('Ping', e)
Esempio n. 8
0
 def __connect(self):
     self.__cm = ConnectionManager(self.__host, self.__port)
     self.__cm.connect()
Esempio n. 9
0
    def testHDBBarrier(self):
        """ Creates agent and test adapter. Create remote source and CDC """
        env_dict = str(os.environ)
        #print env_dict
        #self.dp.appendTrace(env_dict)
        global remoteSubList
        global virTableList
        global targetTableList
        global remoteTableList
        global src
        global agent
        try:
            if run_test == 1:
                #self.dp.appendTrace(env_dict)
                self.agent_name = self.dp.getAgentName()
                port = str(self.dp.getAgentPort())
                host = self.dp.getAgentHost()
                cursor = self.conn.cursor()
                testapi = DPAdapterApi(self.conn, cursor)

                ra_port = self.dp.ra_port
                remoteTableName='dpagent_testAdapter_emp'
                remoteTableOwner='SYSTEM'
                remoteTableSchema="COL1 INT"
                agent['agent_host'] = host
                agent['agent_port'] = port
                agent['agent_dir'] = '/usr/sap/dp/' + self.agent_name
                agent['agent_name'] = self.agent_name
                agent['java_path'] = '/usr/sap/dp/java/bin'

                src['admin_port'] = str(ra_port)

                consrc = ConnectionManager()
                self.conn_src = consrc.createConnection(address=src['pds_host_name'], port=string.atoi(src['pds_port_number']), user="******", password='******' , autocommit=True)
                cursor_src = self.conn_src.cursor()
                testSrc = DPAdapterRemoteHDB(self.conn_src, cursor_src)

                # cleanup RA system objects from source HDB in case these objects left in previous test failure
                testSrc.cleanRAObjects(src['pds_username'])

                # create pds_username on source HDB
                userType = "admin_user"
                testSrc.createUser(userType, src['pds_username'], src['pds_password'])

                self.dp.appendTrace('create agent')
                testapi.createAgent(agent)

                self.dp.appendTrace('create adapter')
                testapi.createAdapter(src['adapter_name'], self.agent_name)

                self.dp.appendTrace('create remote source')
                adapterType = "hana"
                testapi.createRemoteSource(adapterType, src, agent)


                dummy['dumTableName'] = "DPDUMMY"
                dummy['dumTableOwner'] = src['pds_username'].upper()
                dummy['dumTableSchema'] = "COL1 INT PRIMARY KEY"
                dummy['dumSubName'] = "SUB_DPDUMMY"
                dummy['dumVTableName'] = testapi.getVirtualTableName(src['pds_username'], dummy['dumTableName'])
                dummy['dumTTableName'] = 'T_' + dummy['dumTableName']                
                targetTableOwner = "SYSTEM"
                virtualTableOwner = "SYSTEM"

                testSrc.createTable(dummy['dumTableName'], dummy['dumTableOwner'], dummy['dumTableSchema'])
                insert_data = 10000
                insertDataList = []
                i = 1
                rowcnt = 3
                while (i < rowcnt + 1):
                    ini_data = str(i + insert_data)
                    insertDataList.append(ini_data)
                    i += 1
                testSrc.insertManyRows(dummy['dumTableName'],  dummy['dumTableOwner'], insertDataList)

                self.dp.appendTrace('create virtual table')
                testapi.createVirtualTable(src['RemoteSourceName'], dummy['dumTableOwner'], dummy['dumTableName'], dummy['dumVTableName'])
                virTableList.append(dummy['dumVTableName'])

                self.dp.appendTrace('create target table')
                testapi.createTargetTable(dummy['dumTTableName'], dummy['dumVTableName'])
                targetTableStr = targetTableOwner + "." + dummy['dumTTableName']
                targetTableList.append(targetTableStr)

                self.dp.appendTrace('create remote subscription')
                testapi.createRemoteSubscription(dummy['dumSubName'], dummy['dumVTableName'], dummy['dumTTableName'])
                remoteSubList.append(dummy['dumSubName'])

                self.dp.appendTrace('QUEUE')
                status = "QUEUE"
                testapi.alterRemoteSubscription(dummy['dumSubName'], status)

                self.dp.appendTrace('initial load')
                virtualTableWhereClause = "None"
                exprowcnt = testSrc.getRowCount(dummy['dumTableName'], dummy['dumTableOwner'], virtualTableWhereClause)
                virtualTableColumns = '*'
                timeout = 5
                testapi.iniLoadTargetTable( dummy['dumVTableName'], virtualTableColumns, exprowcnt, dummy['dumTTableName'], targetTableOwner, timeout, virtualTableOwner, virtualTableWhereClause)

                self.dp.appendTrace('DISTRIBUTE')
                status = 'DISTRIBUTE'
                testapi.alterRemoteSubscription(dummy['dumSubName'], status)

                self.dp.appendTrace('insert and compare data')
                #insert to source
                testSrc.insertManyRows(dummy['dumTableName'], dummy['dumTableOwner'], ["12345"], True, "None")
                print "Checking if INSERT replicated correctly to HANA ..."
                selectSql = 'SELECT * FROM ' +  targetTableOwner + '.' + dummy['dumTTableName'] + ' ORDER BY COL1 ASC'
                resultset = "testHDBBarrier1i"
                self.compareRepData(selectSql, resultset)

                setClause = "COL1 = 678910"
                updateWhereClause = "COL1 = 12345"
                testSrc.updateRow(dummy['dumTableName'], dummy['dumTableOwner'], setClause, updateWhereClause)
                print "Checking if UPDATE replicated correctly to HANA ..."
                resultset = "testHDBBarrier1u"
                self.compareRepData(selectSql, resultset)

                deleteWhereClause = "COL1 > 10002"
                testSrc.deleteRow(dummy['dumTableName'], dummy['dumTableOwner'], deleteWhereClause)
                print "Checking if DELETE replicated correctly to HANA ..."
                resultset = "testHDBBarrier1d"
                self.compareRepData(selectSql, resultset)

                print 'Test complete successful !'

            else:
                pass
        except dbapi.Error, err:
            self.dp.appendTrace('Error in the test')
            self.dp.appendTrace(str(err))
	    self.assertEqual("True", "False","Fail to create agent instance!")
            pass
Esempio n. 10
0
# Primary control over the application

from connectionManager import ConnectionManager
from tables import Tables

# get connection to DynamoDB instance
conn = ConnectionManager()
tables = Tables()

tables.create_category_tbl(conn.db)

# delete table code:
#tables.delete_category_tbl(conn.db)