Question: Key Value Store For this coding problem, we are writing a simple key - value store. There are two files ( server . py and
Key Value Store
For this coding problem, we are writing a simple keyvalue store. There are two files serverpy and client.py and each needs to define two classes Server and Client respectively. The Server class holds a keyvalue store, that can be updated and accessed by the Client class who has a Server instance passed into its constructor Multiple servers can hold different data, but when a Client instances syncservers method is called, all the servers must consolidate information. If two servers have values stored with the same key, the most recent assignment is preserved.
The Client class must support the following methods:
put, which takes a key and a value. It should store the information in the server.
get, which takes a key. It should return the value that is associated with that key from the server. Return None if not value exists.
syncservers, which takes no arguments. It should cause all servers to merge their information.
Please implement syncservers
here are the test cases please ensure that the code passes all the test cases:
import sqlite
import unittest
from pprint import pprint
import sys
import os
syspath.appendhomecodioworkspacestudentcode
from client import Client
from server import Server
class TestCheckServerClientunittestTestCase:
def testexamplesingleclientself:
s Server
c Clients
assert cgethello is None
cputhello "world"
assert cgethello "world"
cputhello "WORLD!"
assert cgethello "WORLD!"
def testexamplemultipleclientsself:
s Server
c Clients
c Clients
assert cgethello is None
assert cgethello is None
cputhello "world"
assert cgethello "world"
assert cgethello "world"
c Clients
cputhello "WORLD!"
assert cgethello "WORLD!"
assert cgethello "WORLD!"
assert cgethello "WORLD!"
def testexamplemultipleserversself:
s Server
c Clients
c Clients
cputhello "world"
assert cgethello "world"
assert cgethello "world"
s Server
c Clients
cputjosh "nahum"
assert cgetjosh "nahum"
assert cgetjosh is None
assert cgethello is None
c Clients
assert cgetjosh "nahum"
def testexampleserversyncnokeyoverlapself:
s Server
c Clients
c Clients
cputhello "world"
assert cgethello "world"
assert cgethello "world"
s Server
c Clients
cputjosh "nahum"
assert cgetjosh "nahum"
assert cgetjosh is None
assert cgethello is None
c Clients
assert cgetjosh "nahum"
s Server
c Clients
csyncservers
assert cgetjosh "nahum"
assert cgethello "world"
assert cgetjosh "nahum"
assert cgethello "world"
assert cgetjosh "nahum"
assert cgethello "world"
def testexampleserverrepeatedkeysself:
s Server
c Clients
c Clients
cputhello "world"
assert cgethello "world"
assert cgethello "world"
cputferret "dany"
s Server
c Clients
cputjosh "nahum"
assert cgetjosh "nahum"
assert cgetjosh is None
assert cgethello is None
cputferret "ghost"
c Clients
assert cgetjosh "nahum"
assert cgetferret "ghost"
assert cgetferret "dany"
s Server
c Clients
csyncservers
assert cgetjosh "nahum"
assert cgethello "world"
assert cgetferret "ghost"
assert cgetjosh "nahum"
assert cgethello "world"
assert cgetferret "ghost"
assert cgetjosh "nahum"
assert cgethello "world"
assert cgetferret "ghost"
cputferret "racetrack"
assert cgetferret "racetrack"
assert cgetferret "ghost"
Once again please ensure the syncserver function is implemented and the code passes every test case provided
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
