def client_df7(send_q, recv_q, server_ready, client_ready): server_name = recv_q.get() df = Dataframe("CLIENT_TEST", [Blocker], details=server_name, resolver={Blocker: blocker_merge_func}) send_q.put(df.details) #print ("Client at start:", df.versioned_heap.version_graph.nodes.keys()) # Waiting at point C1 #print ("Waiting for C1") server_ready.wait() server_ready.clear() #print ("Client after waiting for server first time.:", df.versioned_heap.version_graph.nodes.keys()) # Pull from the server. df.pull() #print ("Client after first pull:", df.versioned_heap.version_graph.nodes.keys()) df.checkout() blockers = df.read_all(Blocker) assert (1 == len(blockers)) b1 = blockers[0] assert (b1.prop == 1) #print ("Setting S1") # Setting point S1 client_ready.set() b1.prop = 10 assert (b1.prop == 10) df.commit() #print ("Client after first modification:", df.versioned_heap.version_graph.nodes.keys()) # Waiting at point C2 #print ("Waiting for C2") server_ready.wait() server_ready.clear() #print ("Client after waiting for server:", df.versioned_heap.version_graph.nodes.keys()) df.push() #print ("Client after pushing:", df.versioned_heap.version_graph.nodes.keys()) # Setting point S2 #print ("Setting S2") client_ready.set() # Waiting at point c3 #print ("Waiting for C3") server_ready.wait() server_ready.clear() df.pull() #print ("Client after pulling second time:", df.versioned_heap.version_graph.nodes.keys()) df.checkout() assert (b1.prop == 10) b1.prop = 5 df.commit() df.push() # Setting point S3 #print ("Setting S3") client_ready.set() # Waiting at point c4 #print ("Waiting for C4") server_ready.wait() server_ready.clear()
def client_df7(send_q, recv_q, server_ready, client_ready): server_name = recv_q.get() df = Dataframe("CLIENT_TEST", [Blocker], details=server_name) send_q.put(df.details) #print ("Client at start:", df.versioned_heap.version_graph.nodes.keys()) # Waiting at point C1 #print ("Waiting for C1") server_ready.wait() server_ready.clear() #print ("Client after waiting for server first time.:", df.versioned_heap.version_graph.nodes.keys()) # Pull from the server. df.pull() #print ("Client after first pull:", df.versioned_heap.version_graph.nodes.keys()) df.checkout() blockers = df.read_all(Blocker) assert (1 == len(blockers)) b1 = blockers[0] assert (b1.prop == 1) #print ("Setting S1") # Setting point S1 client_ready.set() b1.prop = 10 assert (b1.prop == 10) df.commit() #print ("Client after first modification:", df.versioned_heap.version_graph.nodes.keys()) # Waiting at point C2 #print ("Waiting for C2") server_ready.wait() server_ready.clear() #print ("Client after waiting for server:", df.versioned_heap.version_graph.nodes.keys()) df.push() #print ("Client after pushing:", df.versioned_heap.version_graph.nodes.keys()) # Setting point S2 #print ("Setting S2") client_ready.set() # Waiting at point c3 #print ("Waiting for C3") server_ready.wait() server_ready.clear() df.pull() #print ("Client after pulling second time:", df.versioned_heap.version_graph.nodes.keys()) df.checkout() assert (b1.prop == 10) b1.prop = 5 df.commit() df.push() # Setting point S3 #print ("Setting S3") client_ready.set() # Waiting at point c4 #print ("Waiting for C4") server_ready.wait() server_ready.clear()
def client_df4(send_q, recv_q, server_ready, client_ready): server_name = recv_q.get() df = Dataframe("CLIENT_TEST", [Counter], details=server_name, resolver={Counter: counter_merge_func}) send_q.put(df.details) #print ("Client at start:", df.versioned_heap.version_graph.nodes.keys()) # Waiting at point C1 #print ("Waiting for C1") server_ready.wait() server_ready.clear() #print ("Client after waiting for server first time.:", df.versioned_heap.version_graph.nodes.keys()) # Pull from the server. df.pull() #print ("Client after first pull:", df.versioned_heap.version_graph.nodes.keys()) df.checkout() counters = df.read_all(Counter) cars = df.read_all(Car) assert (1 == len(counters)) assert (0 == len(cars)) c1 = counters[0] assert (c1.count == 1) #print ("Setting S1") # Setting point S1 client_ready.set() c1.count += 1 assert (c1.count == 2) df.commit() #print ("Client after first modification:", df.versioned_heap.version_graph.nodes.keys()) # Waiting at point C2 #print ("Waiting for C2") server_ready.wait() server_ready.clear() #print ("Client after waiting for server:", df.versioned_heap.version_graph.nodes.keys()) df.push() #print ("Client after pushing:", df.versioned_heap.version_graph.nodes.keys()) # Setting point S2 #print ("Setting S2") client_ready.set() # Waiting at point c3 #print ("Waiting for C3") server_ready.wait() server_ready.clear() df.pull() #print ("Client after pulling second time:", df.versioned_heap.version_graph.nodes.keys()) df.checkout() assert (c1.count == 3) # Setting point S3 #print ("Setting S3") client_ready.set()
def __call__(self, main_func: Callable): # Get the dimensions required for the player dataframe start_time = time() while self.time_out == 0 or (time() - start_time) < self.time_out: try: while True: try: df = Dataframe("dimension_getter", [ServerState], details=(self.host, self.port)) except ConnectionRefusedError as e: if (time() - start_time) > self.time_out: raise e else: break df.pull() df.checkout() if df.read_all(ServerState)[0].server_no_longer_joinable: # This server is from an old game and just hasn't exited yet, wait for a new server. sleep(0.1) continue else: break except (ConnectionResetError, struct.error): sleep(0.1) continue # If we know what game were supposed to be playing, then check to make sure # we match the server environment server_state = df.read_all(ServerState)[0] environment_name = server_state.env_class_name dimension_names: [str] = server_state.env_dimensions if self.server_environment is not None and self.server_environment.__name__ != environment_name: raise ValueError( "Client and Server environment mismatch. We are using: {}. Server is using: {}" .format(self.server_environment.__name__, environment_name)) # Create the correct observation type for our connecting dataframe observation_class = Observation(dimension_names) del df def app(*args, **kwargs): client = Node(client_app, dataframe=(self.host, self.port), Types=[Player, observation_class, ServerState], threading=True) client.start(self, main_func, observation_class, dimension_names, self.host, self.auth_key, *args, **kwargs) return app
def client_df4(send_q, recv_q, server_ready, client_ready): server_name = recv_q.get() df = Dataframe("CLIENT_TEST", [Counter], details=server_name) send_q.put(df.details) #print ("Client at start:", df.versioned_heap.version_graph.nodes.keys()) # Waiting at point C1 #print ("Waiting for C1") server_ready.wait() server_ready.clear() #print ("Client after waiting for server first time.:", df.versioned_heap.version_graph.nodes.keys()) # Pull from the server. df.pull() #print ("Client after first pull:", df.versioned_heap.version_graph.nodes.keys()) df.checkout() counters = df.read_all(Counter) cars = df.read_all(Car) assert (1 == len(counters)) assert (0 == len(cars)) c1 = counters[0] assert (c1.count == 1) #print ("Setting S1") # Setting point S1 client_ready.set() c1.count += 1 assert (c1.count == 2) df.commit() #print ("Client after first modification:", df.versioned_heap.version_graph.nodes.keys()) # Waiting at point C2 #print ("Waiting for C2") server_ready.wait() server_ready.clear() #print ("Client after waiting for server:", df.versioned_heap.version_graph.nodes.keys()) df.push() #print ("Client after pushing:", df.versioned_heap.version_graph.nodes.keys()) # Setting point S2 #print ("Setting S2") client_ready.set() # Waiting at point c3 #print ("Waiting for C3") server_ready.wait() server_ready.clear() df.pull() #print ("Client after pulling second time:", df.versioned_heap.version_graph.nodes.keys()) df.checkout() assert (c1.count == 3) # Setting point S3 #print ("Setting S3") client_ready.set()
def __call__(self, main_func: Callable): # Get the dimensions required for the player dataframe start_time = time() while self.time_out == 0 or (time() - start_time) < self.time_out: try: while True: try: df = Dataframe("dimension_getter", [ServerState], details=(self.host, self.port)) except ConnectionRefusedError as e: if (time() - start_time) > self.time_out: raise e else: break df.pull() df.checkout() if df.read_all(ServerState)[0].server_no_longer_joinable: # This server is from an old game and just hasn't exited yet, wait for a new server. sleep(0.1) continue else: break except (ConnectionResetError, struct.error): sleep(0.1) continue dimension_names: [str] = df.read_all(ServerState)[0].env_dimensions observation_class = Observation(dimension_names) del df def app(*args, **kwargs): client = Node(client_app, dataframe=(self.host, self.port), Types=[Player, observation_class, ServerState]) client.start(self, main_func, observation_class, dimension_names, self.host, self.auth_key, *args, **kwargs) return app
def client_df6(send_q, recv_q, server_ready, client_ready): server_name = recv_q.get() df = Dataframe("CLIENT_TEST", [ClassWithCounter, Counter], details=server_name) send_q.put(df.details) # Waiting at point C1 server_ready.wait() server_ready.clear() # Pull from the server. df.pull() df.checkout() ccs = df.read_all(ClassWithCounter) assert (1 == len(ccs)) c = ccs[0] assert ("counter" not in c.__dict__) assert ("oid" not in c.__dict__) assert (c.counter.oid is 0) assert (c.counter.count is 1) assert (c.oid is 0) df.commit() # Setting point S1 client_ready.set()
def client_df6(send_q, recv_q, server_ready, client_ready): server_name = recv_q.get() df = Dataframe("CLIENT_TEST", [ClassWithCounter, Counter], details=server_name, resolver={Counter: counter_merge_func}) send_q.put(df.details) # Waiting at point C1 server_ready.wait() server_ready.clear() # Pull from the server. df.pull() df.checkout() ccs = df.read_all(ClassWithCounter) assert (1 == len(ccs)) c = ccs[0] assert ("counter" not in c.__dict__) assert ("oid" not in c.__dict__) assert (c.counter.oid is 0) assert (c.counter.count is 1) assert (c.oid is 0) df.commit() # Setting point S1 client_ready.set()
def client_df2(send_q, recv_q, server_ready, client_ready): server_name = recv_q.get() df = Dataframe("CLIENT_TEST", [Car], details=server_name) send_q.put(df.details) #print ("Client at start:", df.versioned_heap.version_graph.nodes.keys()) # Waiting at point C1 #print ("Waiting for C1") server_ready.wait() server_ready.clear() #print ("Client after waiting for server first time.:", df.versioned_heap.version_graph.nodes.keys()) # Pull from the server. df.pull() #print ("Client after first pull:", df.versioned_heap.version_graph.nodes.keys()) df.checkout() cars = df.read_all(Car) assert (2 == len(cars)) c1, c2 = cars #print ("Setting S1") # Setting point S1 client_ready.set() c2.yvel = 1 df.commit() #print ("Client after first modification:", df.versioned_heap.version_graph.nodes.keys()) # Waiting at point C2 #print ("Waiting for C2") server_ready.wait() server_ready.clear() #print ("Client after waiting for server:", df.versioned_heap.version_graph.nodes.keys()) df.push() #print ("Client after pushing:", df.versioned_heap.version_graph.nodes.keys()) # Setting point S2 #print ("Setting S2") client_ready.set() # Waiting at point c3 #print ("Waiting for C3") server_ready.wait() server_ready.clear() df.pull() #print ("Client after pulling second time:", df.versioned_heap.version_graph.nodes.keys()) df.checkout() c1 = df.read_one(Car, 0) c2 = df.read_one(Car, 1) assert ("xvel" not in c1.__dict__) assert ("yvel" not in c1.__dict__) assert ("xpos" not in c1.__dict__) assert ("ypos" not in c1.__dict__) assert ("oid" not in c1.__dict__) assert (c1.xvel is 1) assert (c1.yvel is 1) assert (c1.xpos is 0) assert (c1.ypos is 0) assert (c1.oid is 0) assert ("xvel" not in c2.__dict__) assert ("yvel" not in c2.__dict__) assert ("xpos" not in c2.__dict__) assert ("ypos" not in c2.__dict__) assert ("oid" not in c2.__dict__) assert (c2.xvel is 0) assert (c2.yvel is 1) assert (c2.xpos is 0) assert (c2.ypos is 0) assert (c2.oid is 1) # Setting point S3 #print ("Setting S3") client_ready.set()
def client_df1(send_q, recv_q, server_ready, client_ready): server_name = recv_q.get() df = Dataframe("CLIENT_TEST", [Car], details=server_name) send_q.put(df.details) # Waiting at point C1 server_ready.wait() server_ready.clear() # Pull from the server. df.pull() df.checkout() cars = df.read_all(Car) assert (1 == len(cars)) c = cars[0] assert ("xvel" not in c.__dict__) assert ("yvel" not in c.__dict__) assert ("xpos" not in c.__dict__) assert ("ypos" not in c.__dict__) assert ("oid" not in c.__dict__) assert (c.xvel is 1) assert (c.yvel is 0) assert (c.xpos is 0) assert (c.ypos is 0) assert (c.oid is 0) df.commit() # Setting point S1 client_ready.set() # Waiting at point C2 server_ready.wait() server_ready.clear() df.pull() df.checkout() cars = df.read_all(Car) assert (1 == len(cars)) c = cars[0] assert ("xvel" not in c.__dict__) assert ("yvel" not in c.__dict__) assert ("xpos" not in c.__dict__) assert ("ypos" not in c.__dict__) assert ("oid" not in c.__dict__) assert (c.xvel is 1) assert (c.yvel is 1) assert (c.xpos is 0) assert (c.ypos is 0) assert (c.oid is 0) df.commit() df.checkout() c.xpos = 1 c.ypos = 1 c2 = Car(1) df.add_one(Car, c2) df.commit() df.push() # Setting point S2 client_ready.set() # Waiting at point C3 server_ready.wait() server_ready.clear() df.pull() df.checkout() assert (df.read_one(Car, 1) is None) assert (df.read_one(Car, 2) is None) # This does not work yet. Have to figure it out. # limitation of making it a framework rather than # a programming language itself. # Cannot invalidate old references without holding the # reference itself. #assert ("xvel" not in c2.__dict__) #assert ("yvel" not in c2.__dict__) #assert ("xpos" not in c2.__dict__) #assert ("ypos" not in c2.__dict__) #assert ("oid" not in c2.__dict__) #assert (c2.xvel is 0) #assert (c2.yvel is 0) #assert (c2.xpos is 0) #assert (c2.ypos is 0) #assert (c2.oid is 1) #assert (c2.__r_df__ is None) #assert (Car.__r_table__.object_table[1] == { # "oid": {"type": Datatype.INTEGER, "value": 0}, # "xvel": {"type": Datatype.INTEGER, "value": 0}, # "yvel": {"type": Datatype.INTEGER, "value": 0}, # "xpos": {"type": Datatype.INTEGER, "value": 0}, # "ypos": {"type": Datatype.INTEGER, "value": 0} # }) # Setting point S3 client_ready.set()
def client_df5(send_q, recv_q, server_ready, client_ready): server_name = recv_q.get() df = Dataframe("CLIENT_TEST", [Car], details=server_name) send_q.put(df.details) # Waiting at point C1 server_ready.wait() server_ready.clear() # Pull from the server. df.pull() df.checkout() cars = df.read_all(Car) assert (1 == len(cars)) c = cars[0] assert ("xvel" not in c.__dict__) assert ("yvel" not in c.__dict__) assert ("xpos" not in c.__dict__) assert ("ypos" not in c.__dict__) assert ("oid" not in c.__dict__) assert (c.xvel is 1) assert (c.yvel is 0) assert (c.xpos is 0) assert (c.ypos is 0) assert (c.oid is 0) df.commit() # Setting point S1 client_ready.set() # Waiting at point C2 server_ready.wait() server_ready.clear() df.pull() df.checkout() cars = df.read_all(Car) assert (1 == len(cars)) c = cars[0] assert ("xvel" not in c.__dict__) assert ("yvel" not in c.__dict__) assert ("xpos" not in c.__dict__) assert ("ypos" not in c.__dict__) assert ("oid" not in c.__dict__) assert (c.xvel is 1) assert (c.yvel is 1) assert (c.xpos is 0) assert (c.ypos is 0) assert (c.oid is 0) df.commit() df.checkout() c.xpos = 1 c.ypos = 1 c2 = Car(1) df.add_one(Car, c2) df.commit() df.push() # Setting point S2 client_ready.set() # Waiting at point C3 server_ready.wait() server_ready.clear() df.pull() df.checkout() assert (df.read_one(Car, 1) is None) assert (df.read_one(Car, 2) is None) # Setting point S3 client_ready.set()
def client_df5(send_q, recv_q, server_ready, client_ready): server_name = recv_q.get() df = Dataframe("CLIENT_TEST", [Car], details=server_name) send_q.put(df.details) # Waiting at point C1 server_ready.wait() server_ready.clear() # Pull from the server. df.pull() df.checkout() cars = df.read_all(Car) assert (1 == len(cars)) c = cars[0] assert ("xvel" not in c.__dict__) assert ("yvel" not in c.__dict__) assert ("xpos" not in c.__dict__) assert ("ypos" not in c.__dict__) assert ("oid" not in c.__dict__) assert (c.xvel is 1) assert (c.yvel is 0) assert (c.xpos is 0) assert (c.ypos is 0) assert (c.oid is 0) df.commit() # Setting point S1 client_ready.set() # Waiting at point C2 server_ready.wait() server_ready.clear() df.pull() df.checkout() cars = df.read_all(Car) assert (1 == len(cars)) c = cars[0] assert ("xvel" not in c.__dict__) assert ("yvel" not in c.__dict__) assert ("xpos" not in c.__dict__) assert ("ypos" not in c.__dict__) assert ("oid" not in c.__dict__) assert (c.xvel is 1) assert (c.yvel is 1) assert (c.xpos is 0) assert (c.ypos is 0) assert (c.oid is 0) df.commit() df.checkout() c.xpos = 1 c.ypos = 1 c2 = Car(1) df.add_one(Car, c2) df.commit() df.push() # Setting point S2 client_ready.set() # Waiting at point C3 server_ready.wait() server_ready.clear() df.pull() df.checkout() assert (df.read_one(Car, 1) is None) assert (df.read_one(Car, 2) is None) # Setting point S3 client_ready.set()
def client_df2(send_q, recv_q, server_ready, client_ready): server_name = recv_q.get() df = Dataframe("CLIENT_TEST", [Car], details=server_name) send_q.put(df.details) #print ("Client at start:", df.versioned_heap.version_graph.nodes.keys()) # Waiting at point C1 #print ("Waiting for C1") server_ready.wait() server_ready.clear() #print ("Client after waiting for server first time.:", df.versioned_heap.version_graph.nodes.keys()) # Pull from the server. df.pull() #print ("Client after first pull:", df.versioned_heap.version_graph.nodes.keys()) df.checkout() cars = df.read_all(Car) assert (2 == len(cars)) c1, c2 = cars #print ("Setting S1") # Setting point S1 client_ready.set() c2.yvel = 1 df.commit() #print ("Client after first modification:", df.versioned_heap.version_graph.nodes.keys()) # Waiting at point C2 #print ("Waiting for C2") server_ready.wait() server_ready.clear() #print ("Client after waiting for server:", df.versioned_heap.version_graph.nodes.keys()) df.push() #print ("Client after pushing:", df.versioned_heap.version_graph.nodes.keys()) # Setting point S2 #print ("Setting S2") client_ready.set() # Waiting at point c3 #print ("Waiting for C3") server_ready.wait() server_ready.clear() df.pull() #print ("Client after pulling second time:", df.versioned_heap.version_graph.nodes.keys()) df.checkout() c1 = df.read_one(Car, 0) c2 = df.read_one(Car, 1) assert ("xvel" not in c1.__dict__) assert ("yvel" not in c1.__dict__) assert ("xpos" not in c1.__dict__) assert ("ypos" not in c1.__dict__) assert ("oid" not in c1.__dict__) assert (c1.xvel is 1) assert (c1.yvel is 1) assert (c1.xpos is 0) assert (c1.ypos is 0) assert (c1.oid is 0) assert ("xvel" not in c2.__dict__) assert ("yvel" not in c2.__dict__) assert ("xpos" not in c2.__dict__) assert ("ypos" not in c2.__dict__) assert ("oid" not in c2.__dict__) assert (c2.xvel is 0) assert (c2.yvel is 1) assert (c2.xpos is 0) assert (c2.ypos is 0) assert (c2.oid is 1) # Setting point S3 #print ("Setting S3") client_ready.set()
def client_df1(send_q, recv_q, server_ready, client_ready): server_name = recv_q.get() df = Dataframe("CLIENT_TEST", [Car], details=server_name) send_q.put(df.details) # Waiting at point C1 server_ready.wait() server_ready.clear() # Pull from the server. df.pull() df.checkout() cars = df.read_all(Car) assert (1 == len(cars)) c = cars[0] assert ("xvel" not in c.__dict__) assert ("yvel" not in c.__dict__) assert ("xpos" not in c.__dict__) assert ("ypos" not in c.__dict__) assert ("oid" not in c.__dict__) assert (c.xvel is 1) assert (c.yvel is 0) assert (c.xpos is 0) assert (c.ypos is 0) assert (c.oid is 0) df.commit() # Setting point S1 client_ready.set() # Waiting at point C2 server_ready.wait() server_ready.clear() df.pull() df.checkout() cars = df.read_all(Car) assert (1 == len(cars)) c = cars[0] assert ("xvel" not in c.__dict__) assert ("yvel" not in c.__dict__) assert ("xpos" not in c.__dict__) assert ("ypos" not in c.__dict__) assert ("oid" not in c.__dict__) assert (c.xvel is 1) assert (c.yvel is 1) assert (c.xpos is 0) assert (c.ypos is 0) assert (c.oid is 0) df.commit() df.checkout() c.xpos = 1 c.ypos = 1 c2 = Car(1) df.add_one(Car, c2) df.commit() df.push() # Setting point S2 client_ready.set() # Waiting at point C3 server_ready.wait() server_ready.clear() df.pull() df.checkout() assert (df.read_one(Car, 1) is None) assert (df.read_one(Car, 2) is None) # This does not work yet. Have to figure it out. # limitation of making it a framework rather than # a programming language itself. # Cannot invalidate old references without holding the # reference itself. #assert ("xvel" not in c2.__dict__) #assert ("yvel" not in c2.__dict__) #assert ("xpos" not in c2.__dict__) #assert ("ypos" not in c2.__dict__) #assert ("oid" not in c2.__dict__) #assert (c2.xvel is 0) #assert (c2.yvel is 0) #assert (c2.xpos is 0) #assert (c2.ypos is 0) #assert (c2.oid is 1) #assert (c2.__r_df__ is None) #assert (Car.__r_table__.object_table[1] == { # "oid": {"type": Datatype.INTEGER, "value": 0}, # "xvel": {"type": Datatype.INTEGER, "value": 0}, # "yvel": {"type": Datatype.INTEGER, "value": 0}, # "xpos": {"type": Datatype.INTEGER, "value": 0}, # "ypos": {"type": Datatype.INTEGER, "value": 0} # }) # Setting point S3 client_ready.set()